Skip to content

Don't require creation of per-thread IOLoops - #5310

Open
gjoseph92 wants to merge 2 commits into
dask:mainfrom
gjoseph92:no-per-thread-ioloop
Open

gjoseph92 wants to merge 2 commits into
dask:mainfrom
gjoseph92:no-per-thread-ioloop

Conversation

@gjoseph92

Copy link
Copy Markdown
Collaborator

Related to #5309. This will still normally create a per-thread IOLoop instance because of AnyThreadEventLoopPolicy, but at least this is the more proper way to write the code. And if we remove AnyThreadEventLoopPolicy, this should still work.

Note this also happens to fix get_client within a task under uvloop (before it would have raised a RuntimeError there was no event loop for the thread, because our AnyThreadEventLoopPolicy was overwritten by uvloop's).

cc @jcrist

  • Tests added / passed
  • Passes black distributed / flake8 distributed / isort distributed

gjoseph92 added a commit to gjoseph92/distributed that referenced this pull request Sep 10, 2021
Just curious to see what fails so far.

With dask#5310 and dask#5311, closes dask#5309 (and ensures `uvloop` will work with everything)
@gjoseph92 gjoseph92 mentioned this pull request Sep 10, 2021
3 tasks
Comment thread distributed/client.py Outdated
find ourselves in contexts when it is better to operate synchronously.
"""
try:
return self._asynchronous and self.loop is IOLoop.current()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrocklin

Copy link
Copy Markdown
Member

It may also be possible to replace this check by comparing something simpler like worker.thread_id == threading.get_ident(). This may be strange in a Jupyter notebook though, which has odd behavior around event loops. wouldn't go too far down this path, but it might be worth inspecting briefly.

This branch has not been deployed

No deployments
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.

3 participants