coiled / feedback

A place to provide Coiled feedback
14 stars 3 forks source link

Windows asyncio subprocess support #43

Closed mrocklin closed 4 years ago

mrocklin commented 4 years ago
(base) C:\Users\mrock>coiled install coiled/default
Creating local conda environment for coiled/default
Traceback (most recent call last):
  File "c:\users\mrock\miniconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\mrock\miniconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\mrock\Miniconda3\Scripts\coiled.exe\__main__.py", line 7, in <module>
  File "c:\users\mrock\miniconda3\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\mrock\miniconda3\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\users\mrock\miniconda3\lib\site-packages\click\core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\mrock\miniconda3\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\mrock\miniconda3\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\users\mrock\miniconda3\lib\site-packages\coiled\cli\install.py", line 69, in install
    asyncio.get_event_loop().run_until_complete(main(account, name))
  File "c:\users\mrock\miniconda3\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "c:\users\mrock\miniconda3\lib\site-packages\coiled\cli\install.py", line 87, in main
    await create_conda_env(name=local_env_name, solved_spec=conda_solved_spec)
  File "c:\users\mrock\miniconda3\lib\site-packages\coiled\cli\install.py", line 140, in create_conda_env
    async for line in run_command_in_subprocess(conda_create_cmd):
  File "c:\users\mrock\miniconda3\lib\site-packages\coiled\utils.py", line 260, in run_command_in_subprocess
    proc = await asyncio.create_subprocess_shell(
  File "c:\users\mrock\miniconda3\lib\asyncio\subprocess.py", line 216, in create_subprocess_shell
    transport, protocol = await loop.subprocess_shell(
  File "c:\users\mrock\miniconda3\lib\asyncio\base_events.py", line 1597, in subprocess_shell
    transport = await self._make_subprocess_transport(
  File "c:\users\mrock\miniconda3\lib\asyncio\base_events.py", line 491, in _make_subprocess_transport
    raise NotImplementedError
NotImplementedError
mrocklin commented 4 years ago

Running python 3.8.5 and coiled 0.18

mrocklin commented 4 years ago

This works

diff --git a/python-api/coiled/cli/install.py b/python-api/coiled/cli/install.py
index 98f3621..4f3748e 100644
--- a/python-api/coiled/cli/install.py
+++ b/python-api/coiled/cli/install.py
@@ -68,7 +68,10 @@ def install(coiled_uri: str):
             f'Invalid coiled_uri, should be in the format of "<account>/<env_name>" but got "{coiled_uri}"'
         )

-    asyncio.get_event_loop().run_until_complete(main(account, name))
+    loop = asyncio.ProactorEventLoop()
+    asyncio.set_event_loop(loop)
+
+    loop.run_until_complete(main(account, name))

But I'm not yet sure why this isn't happening by default.

jrbourbeau commented 4 years ago

Thanks for digging into this @mrocklin!

But I'm not yet sure why this isn't happening by default

Yeah, that's strange. From https://docs.python.org/3/library/asyncio-platforms.html#windows: "Changed in version 3.8: On Windows, ProactorEventLoop is now the default event loop."

mrocklin commented 4 years ago

It is. When I type in get_event_loop() it gives me a ProactorEventLoop, so I'm surprised that this occurred. I'll dig in.

jrbourbeau commented 4 years ago

Closing as this has been resolved upstream