-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
separate SelectorThread into its own object #3029
Conversation
so it can be used on an existing asyncio loop without replacing the loop itself
I have no objections to this change (and I like that it shrinks the getattribute exception list). However, if you're using something like this I also have no objections to you copying this code into an independent project if that's what you decide to do. |
Yeah, I saw your comment on the Python Issue and realized I misunderstood what was going on here because of the inheritance from AbstractEventLoop. I had thought the result of this code was that Thanks for the notes! I'll hold off on the independent package for now, but keep it in mind if this proactor stuff keeps causing problems outside tornado, especially if folks think |
according to spec: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.close The call to _wake_selector would fail with EBADF when close is called a second time
I added one more commit here because I noticed that AddThreadEventLoop.close() wasn't idempotent, which the docs say it should be. |
What are your thoughts on this PR now, after time has passed and you have zeromq/pyzmq#1524? Are you interested in getting it updated and merged or should we just close it? |
This isn't blocking me on anything, so I'm happy with whatever you'd prefer. 63ae59d at least fixes an actual (minor) bug in the expected idempotency of event_loop.close(). |
Alright, I still like this change so I've updated it to be mergeable. Thanks! |
so it can be used on an existing asyncio loop without replacing the loop itself.
e.g.
I'm investigating using the same solution for proactor compatibility in pyzmq, and the hiccup I am encountering is that pyzmq methods don't get invoked until the loop is already running, which means I need to launch the selector thread without replacing the loop itself. Using AddThread seems to work for this, but I thought it seemed cleaner to separate those two stages (run reader/writer in a thread vs define reader/writer methods on the main loop) explicitly. I'm also not at all sure things are being cleaned up properly when I set it up that way.
I was also thinking of making just this functionality a standalone package (e.g. asyncio-selector-thread), what do you think about that? Since this was added for tornado's internal use, feel free to close as out-of-scope for this repo and I'll explore the standalone package myself, which would mostly be exactly the code in this PR.