Skip to content
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

Shutdown the loop's default thread executor at the end of a test #504

Merged

Conversation

marcinbarczynski
Copy link
Contributor

@marcinbarczynski marcinbarczynski commented Nov 23, 2022

The same approach is adopted in IsolatedAsyncioTestCase. It prevents leaking asyncio threads as loop.close() doesn't join them.

Fixes #503

@marcinbarczynski marcinbarczynski force-pushed the shutdown-loop-executor-in-tests branch 3 times, most recently from 0c4755a to a10c49c Compare November 23, 2022 08:27
@agronholm
Copy link
Owner

Surely there is a way to do this on Pythons earlier than 3.9, even if we have to use a private API?

@marcinbarczynski
Copy link
Contributor Author

Surely there is a way to do this on Pythons earlier than 3.9, even if we have to use a private API?

That's true, but it requires copying non-trivial code from Python 3.9+ to anyio and adapting it to Python 3.7 and 3.8 internals. Do you think it's worth the effort?

@agronholm
Copy link
Owner

Yeah, those Python versions will stay supported for a while. Also please add a regression test.

@marcinbarczynski marcinbarczynski force-pushed the shutdown-loop-executor-in-tests branch 5 times, most recently from 56f7777 to ecd414c Compare November 24, 2022 11:44
The same approach is adopted in IsolatedAsyncioTestCase. It prevents
leaking asyncio threads as loop.close() doesn't join them.

BaseEventLoop.shutdown_default_executor was introduced in Python 3.9.
For earlier versions, this commit introduces an adapted version of
the method: _shutdown_default_executor. However, it doesn't work
with uvloop < 0.15.0 because, uvloop doesn't expose
_default_executor attribute. It's rather a minor issue as
uvloop 0.15.0 is 2 years old - in such case this commit is a no-op.

Fixes agronholm#503
@marcinbarczynski
Copy link
Contributor Author

Yeah, those Python versions will stay supported for a while. Also please add a regression test.

Done.

@agronholm agronholm merged commit ff5c811 into agronholm:master Nov 26, 2022
@agronholm
Copy link
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Thread leaks in async tests marked with @pytest.mark.anyio
2 participants