-
Notifications
You must be signed in to change notification settings - Fork 152
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
Clean up pending tasks when event_loop fixture leaves scope #200
Comments
IMHO you are responsible to |
There are very few things that need to be solved for the corresponding PR to get merged. Hence I'm marking this as good first issue. |
Can I take this issue and solve it? @seifertm |
@priyanshu-panwar Of course, give it a try. The existing PR is generally good. My main concerns are the use of non-public CPython APIs (i.e. the use of |
@seifertm One thought I had is that an alternative, at least on Python 3.11 and above is to use the new asyncio.Runner. @pytest.fixture(scope="session")
def event_loop() -> Iterator[asyncio.AbstractEventLoop]:
with asyncio.Runner() as runner:
yield runner.get_loop() That would at least help with the cleanup and avoid using non-public API's. A loop factory could be provided for use-cases like using |
@samypr100 I fully agree that using asyncio.Runner is the way to go for pytest-asyncio in the future. As we speak, pytest-asyncio v0.23 is in the making which contains substantial changes, such as the deprecation of event_loop fixture overrides. I don't want to include any additional functionality, because the release is big enough as it is. In fact, the v0.22 had to be retracted due to problems connected to the deprecation. Once the deprecation is in place, we can come back to this issue and investigate replacing existing calls to |
@seifertm In order to attempt help, I took a stab at a working |
I'm not sure if this would be considered a bug or a feature :)
I noticed that in some of my tests, my long running tasks (e.g. while loops) were throwing warnings about tasks being destroyed but were pending. I guess this is happening because the loop is closed at the end of a test, but my while loops are still while'ing
In my projects, I maintain a cleanup function at the end of my main function to keep track of what tasks are still alive, then I cancel them before shutting down the loop. The tasks themselves are running forever intentionally, and they should only shut down when the app shuts down (and I shut down gracefully for cleaner logs).
I was wondering if this functionality should be added to the event_loop fixture (maybe optionally) to silence warnings where they don't really belong? Or, is this the responsibility of the developer via a custom fixture?
The text was updated successfully, but these errors were encountered: