Giter Site home page Giter Site logo

Comments (7)

takluyver avatar takluyver commented on September 27, 2024

I think this comment points to the issue:

# This is for Linux, which requires the blocking form
# of waitpid to # get status of a defunct process.
# This is super-lame. The flag_eof would have been set
# in read_nonblocking(), so this should be safe.

In interact, it's not using read_nonblocking(), so flag_eof is not sent, and it doesn't discover that the process has exited. If I'm right, fix coming up.

from pexpect.

takluyver avatar takluyver commented on September 27, 2024

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 spawn() class, which creates a pty, starts a new process in that pty, and tracks both the pty and the process. i.e. reduce that code sample to:

import pexpect
c = pexpect.spawn(['/bin/bash'])
c.interact()

from pexpect.

aidanhs avatar aidanhs commented on September 27, 2024

Good point. I think this behaviour is probably historical, I'll need see if I can remember why I wrote it like that...
It may well be that just using plain pexpect is the best way to do this.

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."
Specifically, running on 2.4:

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

from pexpect.

aidanhs avatar aidanhs commented on September 27, 2024

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.
I'm not sure if it's possible to reproduce the issue for the original use case inside paramiko, but I do think it'd be preferable if pexpect have the behaviour it had before 3.0.

from pexpect.

takluyver avatar takluyver commented on September 27, 2024

Well, I wouldn't quite call throwing an error 'terminating correctly', but I take your point. Pexpect now catches that error, but it should probably stop looping when it does.

from pexpect.

jquast avatar jquast commented on September 27, 2024

Yes, this bug was introduced by c7a180a -- @takluyver, see my pull request -- how does this match to what you intended with this comment?

from pexpect.

takluyver avatar takluyver commented on September 27, 2024

#72 is now merged, closing this.

from pexpect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.