Repository navigation
bpo-37137: Fix test_asyncio: use TestCase.set_event_loop() - #13779
Conversation
Replace asyncio.set_event_loop() with TestCase.set_event_loop() of test_asyncio.utils: this method calls TestCase.close_loop() which waits until the executor completes, to avoid leaking dangling threads. Inherit from test_asyncio.utils.TestCase rather than unittest.TestCase.
asvetlov
left a comment
There was a problem hiding this comment.
LGTM and thank you very much.
You are jedi for tests fighting!
| self.loop.close() | ||
| asyncio.set_event_loop(None) | ||
| super().tearDown() | ||
| self.set_event_loop(self.loop) |
There was a problem hiding this comment.
@asvetlov: I'm not sure about this change, but since tests still pass, it seems like the change is safe.
To be clear: I have no idea if this PR fix the issue, since I'm unable to reproduce https://bugs.python.org/issue37137
Well, I modified regrtest to make a test fail if there is "dangling thread", so I know this issue very well. I also reported https://bugs.python.org/issue34037 And I wrote TestCase.close_loop() and TestCase.set_event_loop() :-) |
…13779) Replace asyncio.set_event_loop() with TestCase.set_event_loop() of test_asyncio.utils: this method calls TestCase.close_loop() which waits until the executor completes, to avoid leaking dangling threads. Inherit from test_asyncio.utils.TestCase rather than unittest.TestCase.
Replace asyncio.set_event_loop() with TestCase.set_event_loop() of
test_asyncio.utils: this method calls TestCase.close_loop() which
waits until the executor completes, to avoid leaking dangling
threads.
https://bugs.python.org/issue37137