[issue33918] Hooking into pause/resume of iterators/coroutines

2019-05-29 Thread Andrew Svetlov
Change by Andrew Svetlov : -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracker ___ ___ Python-

[issue33918] Hooking into pause/resume of iterators/coroutines

2019-05-29 Thread Andrew Svetlov
Andrew Svetlov added the comment: decimal was changed from threading.local to contextvar usage. The module is "safe" not only for asyncio but for threading, trio etc. unittest.mock doesn't use explicit context all for patching. It changes global interpreter-wide objects instead. So, mock.patc

[issue33918] Hooking into pause/resume of iterators/coroutines

2018-06-26 Thread Liran Nuna
Liran Nuna added the comment: > That's still doable with contextvars. You just need a custom mock-like object > (or library) that stores its settings/state in a context variable. contextvars only work with asyncio, what about the iterator case? In addition, you can't possibly expect authors

[issue33918] Hooking into pause/resume of iterators/coroutines

2018-06-20 Thread Yury Selivanov
Yury Selivanov added the comment: > Imagine the context manager is mock.patch used in testing and you want to run > two tests in "parallel", each with a different mocked method. mock.patch > isn't aware of `await` so patching will be incorrect. That's still doable with contextvars. You just

[issue33918] Hooking into pause/resume of iterators/coroutines

2018-06-20 Thread Liran Nuna
Liran Nuna added the comment: > You should try to use the contextvars module that was specifically created to > handle local context state (for tasks & coroutines). Yury, from my original report: > I'm aware that this particular problem could be solved with the new context > variables intro

[issue33918] Hooking into pause/resume of iterators/coroutines

2018-06-20 Thread Yury Selivanov
Yury Selivanov added the comment: You should try to use the contextvars module that was specifically created to handle local context state (for tasks & coroutines). -- ___ Python tracker ___

[issue33918] Hooking into pause/resume of iterators/coroutines

2018-06-20 Thread Liran Nuna
Liran Nuna added the comment: I would like to stress this issue happens with iterators as well, and this isn't a unique issue to asyncio only. I would like to propose four new magic methods for context managers to solve this: __pause__, __resume__, __apause__ and __aresume__ which will be c

[issue33918] Hooking into pause/resume of iterators/coroutines

2018-06-20 Thread Ned Deily
Change by Ned Deily : -- components: +asyncio -Interpreter Core nosy: +asvetlov, yselivanov versions: -Python 3.4, Python 3.5 ___ Python tracker ___ __

[issue33918] Hooking into pause/resume of iterators/coroutines

2018-06-20 Thread Liran Nuna
New submission from Liran Nuna : 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 bes