New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IsolatedAsyncioTestCase freezes when exception is raised #83282
Comments
IsolatedAsyncioTestCase freezes whenever an exception that inherits from BaseException is raised: import unittest
class TestHangsForever(unittest.IsolatedAsyncioTestCase):
async def test_hangs_forever(self):
raise BaseException("Hangs forever")
if __name__ == "__main__":
import unittest
unittest.main() A kind of similar issue present on 3.7 was fixed on 3.8 here https://github.com/python/cpython/blob/3.8/Lib/asyncio/events.py#L84, where BaseExceptions would not be correctly handled by the event loop, this seems somewhat related. I had a look at IsolatedAsyncioTestCase implementation, did not spot any obvious broken thing there, I could use some light here. Thanks. |
Here is a variant that also hangs, I suspect for the same reason. The task raises asyncio.CancelledError which inherits from BaseException and my guess is it somehow kills the event loop. import asyncio
import unittest
class DemonstrateHang(unittest.IsolatedAsyncioTestCase):
async def test_hang(self):
task = asyncio.create_task(asyncio.sleep(2))
await asyncio.sleep(0.1)
task.cancel()
await task
# this also hangs: await asyncio.wait_for(task, 5) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: