python-trio / trio-asyncio

a re-implementation of the asyncio mainloop on top of Trio
Other
188 stars 37 forks source link

add_signal_handler should raise NotImplementedError on Windows #85

Open pquentin opened 4 years ago

pquentin commented 4 years ago

uvicorn relies on this behavior: https://github.com/encode/uvicorn/blob/77468df/uvicorn/main.py#L568-L577. Running the code in #84 results in the following traceback on Windows:

{PATH}trio_asyncio\_base.py:20: TrioDeprecationWarning: trio.hazmat is deprecated since Trio 0.15.0; use trio.lowlevel instead (https://github.com/python-trio/trio/issues/476)
  from trio.hazmat import wait_for_child
{PATH}trio_asyncio\_loop.py:267: TrioAsyncioDeprecationWarning: Using trio-asyncio outside of a Trio event loop is deprecated since trio-asyncio 0.10.0 with no replacement
  return _trio_policy.new_event_loop()
Traceback (most recent call last):
  File ".\server.py", line 20, in <module>
    trio_asyncio.run(trio_asyncio.aio_as_trio(server.serve))
  File "{PATH}trio_asyncio\_loop.py", line 429, in run
    return trio.run(_run_task, proc, args)
  File "{PATH}trio\_core\_run.py", line 1795, in run
    raise runner.main_task_outcome.error
  File "{PATH}trio_asyncio\_loop.py", line 427, in _run_task
    return await proc(*args)
  File "{PATH}trio_asyncio\_adapter.py", line 56, in __call__
    return await self.loop.run_aio_coroutine(f)
  File "{PATH}trio_asyncio\_base.py", line 240, in run_aio_coroutine
    return await run_aio_future(fut)
  File "{PATH}trio_asyncio\_util.py", line 45, in run_aio_future
    res = await trio.hazmat.wait_task_rescheduled(abort_cb)
  File "{PATH}trio\_core\_traps.py", line 165, in wait_task_rescheduled
    return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
  File "{PATH}outcome\_sync.py", line 111, in unwrap
    raise captured_error
  File "{PATH}trio_asyncio\_adapter.py", line 19, in _call_defer
    return await proc(*args, **kwargs)
  File "{PATH}uvicorn\main.py", line 393, in serve
    self.install_signal_handlers()
  File "{PATH}uvicorn\main.py", line 565, in install_signal_handlers
    loop.add_signal_handler(sig, self.handle_exit, sig, None)
  File "{PATH}trio_asyncio\_base.py", line 488, in add_signal_handler
    self._check_signal(sig)
AttributeError: 'TrioEventLoop' object has no attribute '_check_signal'
pquentin commented 4 years ago

Fixing this would allow to run FastAPI with uvicorn on Windows: https://gitter.im/python-trio/general?at=5ee0cc5d49260560aa512a42

njsmith commented 4 years ago

It looks like it would also be ok if add_signal_handler simply worked on Windows?

pquentin commented 4 years ago

Yes, I think that would work too!