[Python-ideas] Letting context managers react to yields inside their scope

Yury Selivanov yselivanov.ml at gmail.com
Thu Apr 30 06:26:13 CEST 2015


On 2015-04-29 8:53 PM, Nick Coghlan wrote:
> * Can the same context be safely accessed from multiple threads
> concurrently? At different points in time?

In one of my context implementations (closed source) I
monkey-patch threading module to actually track when
threads are started to preserve the context information.

Internally, the data storage is a tree, which branches
with control points each time the context is modified.

This way it's possible to see all data that was added
to context "on the way" to the point that is currently
executing by Python.

> * Is there a "default context" which applies if no other context has
> been explicitly activated?

In all implementations I myself wrote, I always had
a root context.  But I don't like this design, especially
for something generic in the standard library, where
you want access to this root object to be namespaced
(i.e. numpy cannot conflict with decimal by using the
same key).

I'm OK with some central hidden root context though,
exposed only via an API for event loops, pools, etc, to
facilitate the context switching.

Thanks,
Yury


More information about the Python-ideas mailing list