This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Liran Nuna
Recipients Liran Nuna
Date 2018-06-20.18:24:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1529519056.15.0.56676864532.issue33918@psf.upfronthosting.co.za>
In-reply-to
Content
An interesting property of async programming is that execution order is nondeterministic and async function "pause" and "resume" execution as events come in.

This can play havok with context managers, especially ones that wrap a global state change. I can best explain it with code - see attached file.

If you were to run this, you'd notice that "Should be logged" does not get logged - this is because the execution order runs the context manager immediately and that affects the entire batch (created by asyncio.gather).

Is there a way to hook into a pause/resume handling of coroutines so this kind of thing could be done correctly? I'm aware that this particular problem could be solved with the new context variables introduced with python3.7, however it is just a simplification of our actual issue.

Iterators also suffer from this issue, as `yield` pauses and resumes execution.
History
Date User Action Args
2018-06-20 18:24:16Liran Nunasetrecipients: + Liran Nuna
2018-06-20 18:24:16Liran Nunasetmessageid: <1529519056.15.0.56676864532.issue33918@psf.upfronthosting.co.za>
2018-06-20 18:24:16Liran Nunalinkissue33918 messages
2018-06-20 18:24:16Liran Nunacreate