FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

proper example completeness by drew-512 · Pull Request #164 · go-python/gpython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (4) .txt  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 3 additions & 0 deletions examples/embedding/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func runWithFile(pyFile string) error {

// See type Context interface and related docs
ctx := py.NewContext(py.DefaultContextOpts())

// This drives modules being able to perform cleanup and release resources
defer ctx.Close()

var err error
if len(pyFile) == 0 {
Expand Down
3 changes: 3 additions & 0 deletions examples/embedding/mylib.module.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func init() {
"GO_VERSION": py.String(fmt.Sprintf("%s on %s %s", runtime.Version(), runtime.GOOS, runtime.GOARCH)),
"MYLIB_VERS": py.String("Vacation 1.0 by Fletch F. Fletcher"),
},
OnContextClosed: func(instance *py.Module) {
fmt.Print("<<< host py.Context of py.Module instance closing >>>\n+++\n")
},
})
}

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ Spring Break itinerary:

I bet Monaco will be the best!

<<< host py.Context of py.Module instance closing >>>
+++
3 changes: 3 additions & 0 deletions examples/multi-context/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func RunMultiPi(numWorkers, numTimes int) time.Duration {
w.ctx.RunCode(jobCode, w.main.Globals, w.main.Globals, nil)
}
workersRunning.Done()

// This drives modules being able to perform cleanup and release resources
w.ctx.Close()
}()
}

Expand Down
1 change: 1 addition & 0 deletions main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func xmain(args []string) {
opts := py.DefaultContextOpts()
opts.SysArgs = args
ctx := py.NewContext(opts)
defer ctx.Close()

if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
Expand Down

Back | FazBrowse Home | New Git URL