diff --git a/examples/embedding/main.go b/examples/embedding/main.go index faa5120e..37f34a7f 100644 --- a/examples/embedding/main.go +++ b/examples/embedding/main.go @@ -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 { diff --git a/examples/embedding/mylib.module.go b/examples/embedding/mylib.module.go index 8a848411..4f2842b2 100644 --- a/examples/embedding/mylib.module.go +++ b/examples/embedding/mylib.module.go @@ -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") + }, }) } diff --git a/examples/embedding/testdata/embedding_out_golden.txt b/examples/embedding/testdata/embedding_out_golden.txt index c7443e07..445e0a65 100644 --- a/examples/embedding/testdata/embedding_out_golden.txt +++ b/examples/embedding/testdata/embedding_out_golden.txt @@ -15,3 +15,5 @@ Spring Break itinerary: I bet Monaco will be the best! +<<< host py.Context of py.Module instance closing >>> ++++ diff --git a/examples/multi-context/main.go b/examples/multi-context/main.go index 7559d60e..4bbeda8b 100644 --- a/examples/multi-context/main.go +++ b/examples/multi-context/main.go @@ -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() }() } diff --git a/main.go b/main.go index 77fe4927..d529646a 100644 --- a/main.go +++ b/main.go @@ -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) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy