Skip to content

Commit 3ccfdff

Browse files
author
Drew O'Meara
committed
example completeness -- now calling ctx.Close()
1 parent 01cbebd commit 3ccfdff

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

examples/embedding/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func runWithFile(pyFile string) error {
2727

2828
// See type Context interface and related docs
2929
ctx := py.NewContext(py.DefaultContextOpts())
30+
31+
// This drives modules being able to perform cleanup and release resources
32+
defer ctx.Close()
3033

3134
var err error
3235
if len(pyFile) == 0 {

examples/multi-context/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ func RunMultiPi(numWorkers, numTimes int) time.Duration {
128128
w.ctx.RunCode(jobCode, w.main.Globals, w.main.Globals, nil)
129129
}
130130
workersRunning.Done()
131+
132+
// This drives modules being able to perform cleanup and release resources
133+
w.ctx.Close()
131134
}()
132135
}
133136

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func xmain(args []string) {
4848
opts := py.DefaultContextOpts()
4949
opts.SysArgs = args
5050
ctx := py.NewContext(opts)
51+
defer ctx.Close()
5152

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

0 commit comments

Comments
 (0)