[Python-ideas] With clauses for generator expressions

Masklinn masklinn at masklinn.net
Thu Nov 15 11:25:27 CET 2012


On 2012-11-15, at 11:08 , Andrew Barnert wrote:
> This is an almost-unrelated side issue. A generator used in a single thread 
> defines a fully deterministic dynamic scope

I think you meant "a context manager" not "a generator", and my example
quite clearly demonstrates that the interaction between context managers
and generators completely break context managers as dynamic scopes.

> , one that can and often should be 
> used for cleanup. The fact that sometimes it's not the right scope for some 
> cleanups, or that you can use them in multithreaded programs

Using context managers on threadlocals means the context manager itself
is in a single-threaded environment, the multithreading is not the
issue, the interaction between context managers and generators is.

> isn't an argument that it should be hard to use them for 
> cleanup when appropriate, is it?

I never wrote that, I only noted that your assertion about the function
you posted (namely that it is "properly written") is dubious and risky.


More information about the Python-ideas mailing list