stencila / py

Stencila for Python
Apache License 2.0
17 stars 1 forks source link

Make matplotlib canvases local to each PythonContext #20

Closed nokome closed 6 years ago

nokome commented 6 years ago

This is a port of issue https://github.com/stencila/desktop/issues/67 as reported by @rgaiacs from the Stencila Desktop repo. That issue was titled "Two (unsaved) documents share the same Python kernel". This is actually not the case (well, is not intended to be the case) - that is, each document has it's own Python execution context (aka kernel). Usually, but not necessarily, all execution context reside within the same Python process.

As shown by the following example, each execution context has it's own variable scope. Note that foo1 is only available in the first document, not in the second - this is the expected behaviour:

image

However, the reported bug relates to the fact that there is a global matplotib backend graphics canvas that gets written to by both contexts:

image