Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Wrap os.forkpty #650

Closed
sophacles opened this issue Sep 13, 2015 · 2 comments
Closed

Wrap os.forkpty #650

sophacles opened this issue Sep 13, 2015 · 2 comments
Labels
Type: Enhancement We can do better through adding this

Comments

@sophacles
Copy link

os.forkpty is used in a few things (for me specifically, pexpect) to launch child processes. On posix this call is implemented in libc, and so in python it is a completely different call than os.fork. However the libc forkpty is just a wrapper around fork, and openpty and login_tty (see http://linux.die.net/man/3/openpty ), so the fundamental operations gevent needs will be the same as for fork.

When using gevent with pexpect (using the head version of master from github anyway), I have had success by creating this wrapper:

https://gist.github.com/sophacles/996f1b18a5ac4263c5b5

This has been tested with linux and osx - python 2.7.10, gevent 1.1b4, pexpect from github master. It works for my usage, there is no guarantee beyond that, but it's a starting point anyway.

Some more thoughts on this:

  • If gevent were to incorporate a proper os.forkpty wrapper, it would not be on windows, as this is pretty much posix specific functionality as I understand it.
  • there may need to be some wrapping to handle blocking nature of the pty fd. This however may not be needed, since it's a bare fd and people who implement things with ptyfork will have to use select and similar anyway, or know enough about the underlying system that they will intuit the need to do do special gevent things if doing a direct os.read (etc) on the fd.
@jamadden jamadden added the Type: Enhancement We can do better through adding this label Sep 16, 2015
@jamadden
Copy link
Member

Thanks for the report. Even though we're late in the beta cycle, since this can be viewed as making an existing feature (waitpid) more complete and correct, and since the implementation is simple and piggybacks on existing tested code, it seems appropriate to me to go ahead and add it for 1.1b5. 0fdf78c Please let us know of any issues.

@sophacles
Copy link
Author

Awesome! Didn't expect it to get addressed so soon thanks.

Please note - I noticed a small typo in the docs and commented on the diff.

hashbrowncipher pushed a commit to hashbrowncipher/gevent that referenced this issue Oct 20, 2018
* Provide friendlier error for missing setup.py
* Added a test case for missing setup.py.
Closes gevent#331.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement We can do better through adding this
Projects
None yet
Development

No branches or pull requests

2 participants