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
Ensure Client connection pool semaphore attaches to the Client's event loop #3546
Conversation
In principle this seems fine. The alternative is to create this in the |
Thanks for the feedback @mrocklin!
I think I've addressed this in my latest commit, but let me know if I misunderstood and you were referring to a different |
Ah, if this requires moving the entire constructor over then that's probably too disruptive (I think?). I would expect the superclass constructor to be called during construction. I hadn't realized that the semaphore was being created within the superclass. I think that the clean way to do what I was proposing would be for the superclass to also have an |
I added As a note, I initially tried to move the creation of a |
I have some thoughts, but they're not particularly strong. I'm curious, what do you think we should do here? As you've been doing more and more maintenance work on dask/distributed my guess is that you're developing your own aesthetic sense of how things should be done here. |
I'm happy with the current state of this PR. I like that we're defining asyncio synchronization primitives inside |
Grand. Merging! |
When creating a
Client
aConnectionPool
is created when theClient
superclass constructor is called heredistributed/distributed/client.py
Lines 712 to 718 in d8d0d4e
Currently, when operating in in synchronous mode, the
ConnectionPool
semaphore attaches the main thread's event loop instead of theClient
's event loop (the same situation as outlined in #3397 (comment)).When we need to acquire the
ConnectionPool
semaphore, we end up getting errors about it being attached to the wrong loop. For example, the following examplecurrently results in a
RuntimeError: Future <Future pending> attached to a different loop
Full traceback:
(Note that I had to run
$ ulimit -n 5000
locally in my terminal to increase the number of allowed connections and trigger acquiring the semaphore)This PR delays the creation of
ConnectionPool.semaphore
to happen inside an async function so it attaches to the correct event loop (like was done in #3437).cc @mrocklin