Skip to content

Commit 6d20a5c

Browse files
authored
Merge pull request #27 from cpunion/subprocess
start subprocess in gradio demo
2 parents 36bcf60 + 8c8860f commit 6d20a5c

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ point.print()
232232
package main
233233

234234
import (
235+
"fmt"
235236
"os"
236237

237238
. "github.com/cpunion/go-python"
@@ -273,8 +274,9 @@ func updateExamples(country string) Object {
273274

274275
func main() {
275276
if len(os.Args) > 2 {
276-
// avoid gradio start subprocesses
277-
return
277+
// start subprocesses
278+
fmt.Println("start subprocess:", os.Args)
279+
os.Exit(RunMain(os.Args))
278280
}
279281

280282
Initialize()

demo/gradio/gradio.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56

67
. "github.com/cpunion/go-python"
@@ -42,8 +43,9 @@ func updateExamples(country string) Object {
4243

4344
func main() {
4445
if len(os.Args) > 2 {
45-
// avoid gradio start subprocesses
46-
return
46+
// start subprocesses
47+
fmt.Println("start subprocess:", os.Args)
48+
os.Exit(RunMain(os.Args))
4749
}
4850

4951
Initialize()

python.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ func RunString(code string) error {
111111
return nil
112112
}
113113

114+
func RunMain(args []string) int {
115+
argc := len(args)
116+
argv := make([]*C.char, argc+1)
117+
for i, arg := range args {
118+
argv[i] = AllocCStr(arg)
119+
}
120+
return int(C.Py_BytesMain(C.int(argc), &argv[0]))
121+
}
122+
114123
// ----------------------------------------------------------------------------
115124

116125
func check(b bool, msg string) {

0 commit comments

Comments
 (0)