curio
curio copied to clipboard
Kernel shuts down when sleep/timeout is too large
When there are no ready tasks, Curio waits until the next deadline. However, on non-Windows systems, there is no upper limit by default, so any sleep/timeout that is too large may cause an OverflowError/OSError to be raised in the kernel context.
import curio
async def main():
try:
await curio.sleep(2_147_484) # for epoll
except BaseException as exc:
print("EXCEPTION:", type(exc))
raise
if __name__ == "__main__":
curio.run(main)
EXCEPTION: <class 'curio.errors.TaskCancelled'>
Traceback (most recent call last):
File "/home/user/workspace/test.py", line 13, in <module>
curio.run(main)
File "/home/user/.local/lib/python3.12/site-packages/curio/kernel.py", line 824, in run
return kernel.run(corofunc, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.12/site-packages/curio/kernel.py", line 146, in run
task = self._runner(coro)
^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.12/site-packages/curio/kernel.py", line 641, in kernel_run
events = selector_select(timeout)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/selectors.py", line 468, in select
fd_event_list = self._selector.poll(timeout, max_ev)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OverflowError: timeout is too large
The quickest solution is to replace max_select_timeout=None with max_select_timeout=86400 (one day).
Related: python/cpython#64692 + python/cpython#78444.