Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Hitting ^D in an 'interact()' causes endless printing of 'exit' #49
Run the following code:
import fdpexpect import pty import os import sys def proc_start(cmd_list): (child_pid, fd) = pty.fork() if child_pid == 0: # The first item of the list in the second argument is the name # of the new program try: os.execvp(cmd_list, cmd_list) except OSError: print "Failed to exec" sys.exit(1) else: return fd fd = proc_start(['/bin/bash']) c = fdpexpect.fdspawn(fd) c.interact()
You get a bash session, it works, you can do things.
Going backwards through pypi versions, I can see this has definitely been broken since 3.0, but was working (it raised an exception instead of printing the same output forever) in 2.4
referenced this issue
May 8, 2014
I think this comment points to the issue:
In interact, it's not using
Oh, no, it's simpler than that. You're using fdpexpect, so the fdspawn object doesn't know about the child process, only the file handle you've given it. The pty continues to exist after the process has died, so it has no way of knowing to stop reading.
Is there a reason you (or rather shutit) are replicating the functionality of pexpect? The easiest way to fix this would be to use the main
Good point. I think this behaviour is probably historical, I'll need see if I can remember why I wrote it like that...
However, it doesn't change the fact that it terminates correctly in 2.4. This contradicts "[...] it has no way of knowing to stop reading."
Traceback (most recent call last): File "test.py", line 21, in <module> c.interact() File "/usr/lib/python2.7/dist-packages/pexpect.py", line 1492, in interact self.__interact_copy(escape_character, input_filter, output_filter) File "/usr/lib/python2.7/dist-packages/pexpect.py", line 1520, in __interact_copy data = self.__interact_read(self.child_fd) File "/usr/lib/python2.7/dist-packages/pexpect.py", line 1510, in __interact_read return os.read(fd, 1000) OSError: [Errno 5] Input/output error
Turns out the reason I did this initially was to connect pexpect to paramiko (which happens to expose a fd for the ssh terminal). I'm going to do it the way you suggested (thanks!) for shutit.
I'll leave this issue open, but I wouldn't call it a huge priority.