[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Jack O'Connor
Jack O'Connor added the comment: Yury, can you help me understand why `hasattr("foo", "bar")` triggers the infinite loop there, but not `print("foo")`? -- ___ Python tracker ___

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Yury Selivanov added the comment: > Yury, can you help me understand why `hasattr("foo", "bar")` triggers the > infinite loop there, but not `print("foo")`? hasattr uses getattr under the hood. getattr raises an AttributeError, and that triggers PyErr_SetError, which has an infinite "while" l

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Yury Selivanov added the comment: Another issue for contextlib: http://bugs.python.org/issue25786 -- ___ Python tracker ___ ___ Python

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Yury Selivanov added the comment: The question is whether we should raise an exception or not: ex.__context__ = ex -- ___ Python tracker ___ _

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Yury Selivanov added the comment: FWIW the bug was identified in issue 25782. I've drafted a patch to fix it, please review. -- ___ Python tracker ___ _

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Yury Selivanov added the comment: > Thanks for chasing this down. Yury, can you suggest a workaround? I'm not sure how to workaround this :( Hopefully we can fix this in 3.5.1. -- ___ Python tracker _

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Jack O'Connor
Jack O'Connor added the comment: Thanks for chasing this down. Yury, can you suggest a workaround? -- ___ Python tracker ___ ___ Pytho

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Changes by Yury Selivanov : -- superseder: infinite loop in reprlib -> CPython hangs on error __context__ set to the error itself ___ Python tracker ___

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Yury Selivanov added the comment: It's not even a reprlib bug: try: raise Exception except Exception as ex: ex.__context__ = ex hasattr(1, 'aa') -- ___ Python tracker __

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Yury Selivanov added the comment: Created another issue for the reprlib bug: issue 25781. It appears we don't even need a generator: import reprlib try: raise RuntimeError except RuntimeError as ex: ex.__context__ = ex reprlib.repr(ex) Closing this one wit

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Yury Selivanov added the comment: Here's a minimal test to reproduce: import reprlib def main(): if 0: yield raise RuntimeError m = main() try: m.send(None) except RuntimeError as ex: ex.__context__ = ex reprlib.repr(ex)

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Yury Selivanov
Yury Selivanov added the comment: Trying to reproduce without contextstack. -- nosy: +ncoghlan ___ Python tracker ___ ___ Python-bugs-

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Guido van Rossum
Guido van Rossum added the comment: Interestingly, it doesn't hang when you raise a different error. There's some new code dealing with the RuntimeError coming out of a generator if it raises StopIteration (instead of returning) introduced by issue #22906. Yury, it looks like you introduced th

[issue25779] deadlock with asyncio+contextmanager+ExitStack

2015-12-02 Thread Jack O'Connor
New submission from Jack O'Connor: The following hangs at 100% CPU on Python 3.5, though not on Python 3.4: 1) Start an asyncio coroutine with run_until_complete(). 2) Inside the coroutine, enter an ExitStack using a with-statement. 3) Inside the with-statement, call ExitStack.enter_context() wi