Skip to content

Remove AnyThreadEventLoopPolicy - #5312

Closed
gjoseph92 wants to merge 5 commits into
dask:mainfrom
gjoseph92:no-AnyThreadEventLoopPolicy
Closed

gjoseph92 wants to merge 5 commits into
dask:mainfrom
gjoseph92:no-AnyThreadEventLoopPolicy

Conversation

@gjoseph92

Copy link
Copy Markdown
Collaborator

Just curious to see what fails so far.

With #5310 and #5311, closes #5309 (and ensures uvloop will work with everything)

  • Closes #xxxx
  • Tests added / passed
  • Passes black distributed / flake8 distributed / isort distributed

Also necessary for `get_client` to work with uvloop
Just curious to see what fails so far.

With dask#5310 and dask#5311, closes dask#5309 (and ensures `uvloop` will work with everything)
@fjetter

fjetter commented Sep 13, 2021

Copy link
Copy Markdown
Member

FYI this custom eventloop policy is one of the things why we currently have to pin pytest-asyncio

@mrocklin

mrocklin commented Sep 13, 2021 via email

Copy link
Copy Markdown
Member

@minrk minrk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 to removing the policy. You can generally ensure a loop would exist in background threads yourself, without enforcing it via a policy, via the same logic applied in the policy.

try:
   loop = asyncio.get_event_loop()
except RuntimeError:
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

Then your code always behaves as desired, regardless of the configured policy.

Comment thread distributed/semaphore.py
@property
def asynchronous(self):
return self.loop is IOLoop.current()
return self.loop is IOLoop.current(instance=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

instance arg is deprecated in tornado 5, and minimum supported tornado is 6.0.3.

@jcrist

jcrist commented Nov 1, 2021

Copy link
Copy Markdown
Member

I've run into an issue that would be best fixed by this getting in.

We currently rely on AnyThreadEventLoopPolicy to automagically create a new event loop in a thread if it doesn't already exist. BUT. Since we use pytest-asyncio, which unconditionally resets the event loop policy at the end of any test decorated with @pytest.mark.asyncio, most of the time this event loop policy isn't even active in our test suite. This leads to all sorts of weird and hard to debug behavior where running a single test will work fine but running the whole suite will fail (since an earlier pytest.mark.asyncio test reset the event loop policy).

What would it take to get this PR in? The instance kwarg to IOLoop.current is marked as deprecated, but doesn't actually warn and has remained constant for the last 3 years in the sourcecode. Relying on it may not be ideal, but also doesn't seem that bad to me. We could also split that code out so we manually check asyncio.get_event_loop() trying IOLoop.current() if that'd be better.

@jcrist

jcrist commented Nov 1, 2021

Copy link
Copy Markdown
Member

FYI this custom eventloop policy is one of the things why we currently have to pin pytest-asyncio

Oop, just noticed that this is apparently a known issue. Spent too long debugging weird failures for no reason then :/.

@gjoseph92

Copy link
Copy Markdown
Collaborator Author

Done in #5531

@gjoseph92 gjoseph92 closed this Nov 29, 2021
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.

get_client within a task creates a new (unused) event loop for every thread

5 participants