-
Notifications
You must be signed in to change notification settings - Fork 71
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
PtyProcess.spawn (and thus pexpect) slowdown in close() loop #50
Comments
Hmm, it's annoying that closerange isn't implemented more efficiently, but I guess there's not much I can do about that. The difficulty with using ptyprocess is also (as a component pulled out of pexpect), old code which has, over the years, attempted to support many platforms. I'm reluctant to make major changes to it, because I don't know all the platforms and use cases where it's running in the wild. So maybe you're better off writing a new module under a different name to do the same thing without all the legacy concerns. I'm happy to link to it from the docs. |
@takluyver well, perhaps you can do something like this instead: python/cpython@5626fff The good news is:
|
The following code in ptyprocess
ptyprocess/ptyprocess/ptyprocess.py
Lines 260 to 269 in 3931cd4
is looping through all possible file descriptors in order to close those (note that
closerange()
implemented as a loop at least on Linux). In case the limit of open fds (akaulimit -n
, akaRLIMIT_NOFILE
, akaSC_OPEN_MAX
) is set too high (for example, with recent docker it is 1024*1024), this loop takes considerable time (as it results in about a millionclose()
syscalls).The solution (at least for Linux and Darwin) is to obtain the list of actually opened fds, and only close those. This is implemented in
subprocess
module in Python3, and there is a backport of it to Python2 called subprocess32.This issue was originally reported to docker: docker/for-linux#502
Other good reason for using
subprocess
(being multithread-safe) is described in #43The text was updated successfully, but these errors were encountered: