-
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
Teardown of the event_loop fixture no longer replaces the event loop policy #192
Conversation
47e3814
to
41c53e1
Compare
41c53e1
to
9ede17b
Compare
I think this will work for us, thank you. |
I'm not really knowledgeable enough to comment, but it seems plausible and we'll certainly try updating versions when it's available. |
@Tinche What are your thoughts on this? |
ping @Tinche :) |
I acknowledge that I created this PR without a previous design discussion. However, I do think this change fixes a real world problem and that the new fixture finalizer is cleaner than the existing code. @Tinche If you can make the time for it, I'd be happy to adjust and rebase this PR or try a different approach based on your input on the matter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
A not-started event loop is a cheap object, it has only a pipe for self-wakeup plus a few empty data containers.
9ede17b
to
5f3dee6
Compare
Thanks for the feedback! I just rebased to master to fix a conflict in the changelog. It turns out the PR is now causing issues on Python 3.8. I'll have another look later today. |
…policy. Signed-off-by: Michael Seifert <[email protected]>
5f3dee6
to
c54943f
Compare
I did the following changes to the PR:
All green now :) |
GJ, merging in. If you're working on event loop teardown, there's an issue laying around here somewhere about shutting down the loop more robustly (#222), think we could incorporate that too? |
Please don't get me wrong -- I'm not opposed to step-by-step improvements. |
My understanding is that everyone is happy, if the event loop policy remains unaltered. I think I found a way to get rid of the code that resets the event loop policy.
Problem
Here is my understanding of the problem:
We need to make sure that each test case runs in an isolated fashion. Therefore, the
event_loop
fixture provides a fresh event loop and is automatically applied to all marked tests. When the fixture goes out of scope, it closes the event loop. Subsequent test cases would run into the following error:This is prevented a dedicated fixture teardown prodecure. The teardown sets the event loop policy to
None
, which also disposes the existing, closed event loop. Subsequent calls toasyncio.get_event_loop()
will return a fresh loop. The problem is that setting the event loop policy to None resets the policy to the system default, which may be undesired.Solution
Instead of resetting the event loop policy, the same effect can be achieved by requesting a new loop to replace the existing, closed event loop:
Considerations
What I dislike about this solution is that a new loop is created during the teardown of the
event_loop
fixture. It feels wrong to do it here. The correct place would be to create a new loop during fixture setup. In fact, the fixture does create another loop so we effectively create two new event loops for each test run. This points to an issue with the order in which the fixtures are evaluated.What are your thoughts on this approach?
Resolves #168
Resolves #188