sagemathinc / cowasm

CoWasm: Collaborative WebAssembly for Servers and Browsers. Built using Zig. Supports Python with extension modules, including numpy.
https://cowasm.org
BSD 3-Clause "New" or "Revised" License
482 stars 23 forks source link

AttributeError: module 'os' has no attribute 'waitstatus_to_exitcode' #7

Closed williamstein closed 1 year ago

williamstein commented 2 years ago

Figure out why this happens. This gets hit very easily, e.g., in the terminal:

>>> import math; help(math)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen _sitebuiltins>", line 103, in __call__
  File "/Users/wstein/build/cocalc/src/data/projects/2c9318d1-4f8b-4910-8da7-68a965514c95/python-wasm/packages/cpython/build/wasm/Lib/pydoc.py", line 2005, in __call__
    # special case these keywords since they are objects too
^^^^^^^^^^^^^^^^^^
  File "/Users/wstein/build/cocalc/src/data/projects/2c9318d1-4f8b-4910-8da7-68a965514c95/python-wasm/packages/cpython/build/wasm/Lib/pydoc.py", line 2064, in help
    ''')

  File "/Users/wstein/build/cocalc/src/data/projects/2c9318d1-4f8b-4910-8da7-68a965514c95/python-wasm/packages/cpython/build/wasm/Lib/pydoc.py", line 1788, in doc
    'global': ('global', 'nonlocal NAMESPACES'),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/wstein/build/cocalc/src/data/projects/2c9318d1-4f8b-4910-8da7-68a965514c95/python-wasm/packages/cpython/build/wasm/Lib/pydoc.py", line 1560, in pager
    # We've hereby abandoned whatever text hasn't been written,
^^^
  File "/Users/wstein/build/cocalc/src/data/projects/2c9318d1-4f8b-4910-8da7-68a965514c95/python-wasm/packages/cpython/build/wasm/Lib/pydoc.py", line 1585, in <lambda>

  File "/Users/wstein/build/cocalc/src/data/projects/2c9318d1-4f8b-4910-8da7-68a965514c95/python-wasm/packages/cpython/build/wasm/Lib/pydoc.py", line 1604, in pipepager
    try:
    ^^^^^
  File "/Users/wstein/build/cocalc/src/data/projects/2c9318d1-4f8b-4910-8da7-68a965514c95/python-wasm/packages/cpython/build/wasm/Lib/subprocess.py", line 736, in <module>
    if not _can_fork_exec:
^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/wstein/build/cocalc/src/data/projects/2c9318d1-4f8b-4910-8da7-68a965514c95/python-wasm/packages/cpython/build/wasm/Lib/subprocess.py", line 1893, in Popen
    delay = 0.0005 # 500 us -> initial delay of 1 ms
                                          ^^^^^^^^^^^
AttributeError: module 'os' has no attribute 'waitstatus_to_exitcode'

Obviously creating a subprocess like this isn't the optimal way to do paging in python-wasm; maybe there is an option or flag to python that changes the behavior?

williamstein commented 1 year ago

I ended up fixing this by (1) better support for the build by adding some header info from wait.h, so the waitstatus_to_exitcode function gets built (of limited use, since no subprocs yet, obviously). Then I just changed the pager to ttypager using python's input() function, with a patch similar to the one for emscripten (but slightly better, since emscripten/pyodide doesn't have a pager).

Also, compare https://github.com/pyodide/pyodide/issues/1557