superconfigure icon indicating copy to clipboard operation
superconfigure copied to clipboard

Asyncio stopped working on Windows with Python 3.12.3 Release

Open igoforth opened this issue 1 year ago • 8 comments

To reproduce:

PS > bin\python
Python 3.12.3 (main, May 25 2024, 19:21:37) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'asyncio' has no attribute 'WindowsSelectorEventLoopPolicy'
>>> asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'asyncio' has no attribute 'WindowsProactorEventLoopPolicy'
>>> asyncio.set_event_loop_policy(asyncio.ProactorEventLoopPolicy())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'asyncio' has no attribute 'ProactorEventLoopPolicy'. Did you mean: 'AbstractEventLoopPolicy'?
>>> asyncio.set_event_loop_policy(asyncio.SelectorEventLoopPolicy())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'asyncio' has no attribute 'SelectorEventLoopPolicy'. Did you mean: 'SelectorEventLoop'?
>>> asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
>>> loop = asyncio.get_event_loop()
<stdin>:1: DeprecationWarning: There is no current event loop
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./Lib/asyncio/events.py", line 699, in get_event_loop
  File "./Lib/asyncio/events.py", line 720, in new_event_loop
  File "./Lib/asyncio/unix_events.py", line 64, in __init__
  File "./Lib/asyncio/selector_events.py", line 66, in __init__
  File "./Lib/asyncio/selector_events.py", line 120, in _make_self_pipe
  File "./Lib/socket.py", line 610, in socketpair
  File "./Lib/socket.py", line 233, in __init__

igoforth avatar May 25 '24 21:05 igoforth

It's possible this could be related to a regression I introduced in the last few days with standard i/o. I believe it's fully fixed at Cosmopolitan HEAD.

jart avatar May 25 '24 21:05 jart

Thanks for all your guys work. I’m a big fan

igoforth avatar May 25 '24 22:05 igoforth

can you post the output python.com --strace when you run these commands?

ahgamut avatar May 25 '24 23:05 ahgamut

can you post the output python.com --strace when you run these commands?

ran as user, lmk if needed as admin

strace.txt

PS > .\bin\python3.12.com --strace 2>strace.txt
>>> import asyncio
>>> asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
>>> asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
>>> asyncio.set_event_loop_policy(asyncio.ProactorEventLoopPolicy())
>>> asyncio.set_event_loop_policy(asyncio.SelectorEventLoopPolicy())
>>> asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
>>> loop = asyncio.get_event_loop()
>>> quit()

igoforth avatar May 25 '24 23:05 igoforth

ok, can you check again with the nightly build now?

ahgamut avatar May 25 '24 23:05 ahgamut

ok, can you check again with the nightly build now?

strace.txt

igoforth avatar May 25 '24 23:05 igoforth

I've had a lot of fun writing bootstrapping code to deploy llamafile with cosmos python and curl. You can check that out here if you're interested https://github.com/igoforth/RWAILib/blob/master/Bootstrap.py

igoforth avatar May 25 '24 23:05 igoforth

For anyone coming back to this, I've had a lot of luck using the Cosmopolitan Python as a first stage to bootstrap a PYZ. The PYZ can retain cross-platform compatibility by modifying its sys.path at runtime with a __main__.py at the root. See the gist here for an example, which takes advantage of wheels and PyBI's to unzip and run a native python within a subprocess: https://gist.github.com/igoforth/0a7e93b20d341d24ba3f10a1283432cb

Limitations: Must use wheels, with no building required at runtime It's probably wrecking your file descriptors

igoforth avatar Jun 02 '24 00:06 igoforth