Skip to content
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

Import of Dask prevents async subprocess management on Windows #7492

Closed
zanieb opened this issue Jan 19, 2023 · 4 comments · Fixed by #7969 · May be fixed by #7494
Closed

Import of Dask prevents async subprocess management on Windows #7492

zanieb opened this issue Jan 19, 2023 · 4 comments · Fixed by #7969 · May be fixed by #7494

Comments

@zanieb
Copy link
Contributor

zanieb commented Jan 19, 2023

Dask changes the event loop policy to the Python 3.7 default instead of the Python 3.8+ default. This event loop does not support spawning subprocesses, which means that if you're writing an application that manages async processes and you've imported Dask, your application will fail with a NotImplementedError from within asyncio.

asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

It looks like this was done because Tornado 6 did not support the new event loop policy, but at tornadoweb/tornado#2608 (comment) they note that this should be fixed in Tornado 6.1.

I see an existing issue at #7434 that notes this breaks a specific Dask cluster type, but more importantly this means that applications that import Dask will not be able to manage subprocesses. This is causing problems over at Prefect since our users import Dask and we need to manage subprocesses within our own library :) we're tracking this at PrefectHQ/prefect#8206 and you can see a reproduction there.

I don't have access to a Windows machine myself right now and am coordinating to produce a MRE that doesn't use Prefect code. However, it should look roughly like:

import asyncio
import dask.distributed

asyncio.run(asyncio.create_subprocess_shell("echo hello world"))

The traceback is also roughly like:

Traceback (most recent call last):
  ...
    process = await asyncio.create_subprocess_shell(
  File "C:\Python310\lib\asyncio\subprocess.py", line 205, in create_subprocess_shell
    transport, protocol = await loop.subprocess_shell(
  File "C:\Python310\lib\asyncio\base_events.py", line 1634, in subprocess_shell
    transport = await self._make_subprocess_transport(
  File "C:\Python310\lib\asyncio\base_events.py", line 498, in _make_subprocess_transport
    raise NotImplementedError
NotImplementedError
@fjetter
Copy link
Member

fjetter commented Jan 20, 2023

There was an attempt to remove this over #5833 but we never followed up. The GH CI logs are unfortunately not available anymore.

@fjetter
Copy link
Member

fjetter commented Jan 20, 2023

I opened #7494 with all the necessary changes for us to switch. Let's see what CI says

@hendrikmakait
Copy link
Member

xref: #7434

@zanieb
Copy link
Contributor Author

zanieb commented Jan 20, 2023

We've added PrefectHQ/prefect#8184 as a workaround for our CLI entrypoints to alleviate the most pressing issues for now. Thanks for hoping on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants