Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
ghost opened this issue Jan 17, 2024 · 6 comments
Open

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

ghost opened this issue Jan 17, 2024 · 6 comments

Comments

@ghost
Copy link

ghost commented Jan 17, 2024

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 (#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
Copy link
Contributor

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:

  • Clone https://github.com/graalvm/mx and put it on your PATH
  • Clone this repo and change into the directory
  • Run mx fetch-jdk labsjdk-ce-21. Run the export line that the command printed
  • Run mx sforceimports
  • Run mx python-svm
  • The path that got printed by the last command is a graalpython interpreter. You can use it to create a virtualenv.

@ghost
Copy link
Author

ghost commented Jan 18, 2024

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
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

  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
Copy link

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants