@@ -12,16 +12,18 @@ const (
12
12
SingleMode CompileMode = "single" // Compile a single (interactive) statement
13
13
)
14
14
15
- // Context is gpython virtual environment instance ("context") , providing a mechanism
15
+ // Context is a gpython environment instance container , providing a high-level mechanism
16
16
// for multiple gpython interpreters to run concurrently without restriction.
17
17
//
18
- // In general, one creates a py.Context (via py.NewContext) for each concurrent goroutine to be running an interpreter.
19
- // In other words, ensure that a py.Context is never concurrently accessed across goroutines.
18
+ // Context instances maintain completely independent environments, namely the modules that
19
+ // have been imported and their state. Modules imported into a Context are instanced
20
+ // from a parent ModuleImpl. For example, since Contexts each have their
21
+ // own sys module instance, each can set sys.path differently and independently.
20
22
//
21
- // RunFile() and RunCode() block until code execution is complete.
22
- // In the future, they will abort early if the parent associated py.Context is signaled .
23
+ // If you access a Context from multiple groutines, you are responsible that access is not concurrent,
24
+ // with the exception of Close() and Done() .
23
25
//
24
- // See examples/multi-ctx
26
+ // See examples/multi-context and examples/embedding.
25
27
type Context interface {
26
28
27
29
// Resolves then compiles (if applicable) the given file system pathname into a py.Code ready to be executed.
@@ -31,6 +33,7 @@ type Context interface {
31
33
ModuleInit (impl * ModuleImpl ) (* Module , error )
32
34
33
35
// RunCode is a lower-level invocation to execute the given py.Code.
36
+ // Blocks until execution is complete.
34
37
RunCode (code * Code , globals , locals StringDict , closure Tuple ) (result Object , err error )
35
38
36
39
// Returns the named module for this context (or an error if not found)
@@ -39,11 +42,12 @@ type Context interface {
39
42
// Gereric access to this context's modules / state.
40
43
Store () * ModuleStore
41
44
42
- // Close signals that is context is about to go out of scope and any internal resources should be released.
43
- // Operations on a py.Context that have closed will generally result in an error.
44
- Close ()
45
+ // Close signals this context is about to go out of scope and any internal resources should be released.
46
+ // Code execution on a py.Context that has been closed will result in an error.
47
+ Close () error
45
48
46
49
// Done returns a signal that can be used to detect when this Context has fully closed / completed.
50
+ // If Close() is called while execution in progress, Done() will not signal until execution is complete.
47
51
Done () <- chan struct {}
48
52
}
49
53
0 commit comments