oracle / graalpython

A Python 3 implementation built on GraalVM
Other
1.17k stars 101 forks source link

AttributeError: module 'os' has no attribute 'fork' #374

Open ghost opened 6 months ago

ghost commented 6 months ago

Hello,

Very sorry for asking again a question, i have this error when running my script, as i saw in other issues, this seem to be an issue on graalpython (https://github.com/oracle/graalpython/issues/370):

  File "/root/.local/vfs/venv/lib/python3.10/site-packages/pexpect/pty_spawn.py", line 205, in __init__
    self._spawn(command, args, preexec_fn, dimensions)
  File "/root/.local/vfs/venv/lib/python3.10/site-packages/pexpect/pty_spawn.py", line 303, in _spawn
    self.ptyproc = self._spawnpty(self.args, env=self.env,
  File "/root/.local/vfs/venv/lib/python3.10/site-packages/pexpect/pty_spawn.py", line 315, in _spawnpty
    return ptyprocess.PtyProcess.spawn(args, **kwargs)
  File "/root/.local/vfs/venv/lib/python3.10/site-packages/ptyprocess/ptyprocess.py", line 230, in spawn
    pid, fd = pty.fork()
  File "/opt/graalpy-24.0.0-dev/lib/python3.10/pty.py", line 102, in fork
    pid = os.fork()
AttributeError: module 'os' has no attribute 'fork'

And do you know when ci for dev will be available?

Again, thanks a lot for all your help,

F.N.

msimacek commented 6 months ago

Hi @fakeNews-jpg. Unfortunately, fork can never be implemented on GraalPy. GraalPy is implemented in Java, and Java wouldn't safely survive forking. It might be possible to patch ptyprocess package to work around it, I'd need to spend some time on it.

I don't know when the CI build will be available, nobody gave me any estimate. If you're eager to try the current master, you can build it yourself. You need to:

ghost commented 6 months ago

Thanks a lot for your answer @msimacek Effectively, if a workaround is possible it will be a great improvement :) For example, https://github.com/ansible/ansible uses os.fork, and is thus not compatible, but marked as compatible on https://www.graalvm.org/python/compatibility/ :/

msimacek commented 6 months ago

It's not marked as compatible, I see ansible-core with 0% passing tests (which doesn't necessarily mean that the package doesn't work, but often the tests timed out or failed to start). The list contains all packages that we test, you have to look at the test percentages. That page is new, I guess it could use some improvement, probably marking the packages with colors in the list.

I grepped ansible sources, fork is only used in async_wrapper module and one cli script. So the rest could still work.

mikehearn commented 5 months ago

A few improvements are possible here:

  1. Fork should be implemented but throw an exception that points users to a documentation page, or at least an explanation.
  2. Usages of fork designed to "daemonize" like that used in Ansible could be replaced by a better approach (e.g. systemd). It's not only GraalPython that doesn't have fork. Windows doesn't have it either.
msimacek commented 5 months ago
  1. Fork should be implemented but throw an exception that points users to a documentation page, or at least an explanation

I'm afraid this could backfire. In general, for platform-specific APIs, libraries often check their presence with hasattr and may have a fallback to something else when the API is not available. If we raise exceptions, we would break those. On CPython on Windows, fork also doesn't exist at all.

mikehearn commented 5 months ago

I guess you could make it callable but hide it from hasattr, but yeah if Python devs are supposed to adapt to missing fork for portability to Windows anyway, then perhaps the stack trace in the first comment should be obvious enough.