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

pexpect 3.3 runs failed when use multiprocessing #86

Closed
bizet opened this Issue Jul 2, 2014 · 3 comments

Comments

Projects
None yet
4 participants
@bizet

bizet commented Jul 2, 2014

I use pexpect (version 3.3) and multiprocessing in python (version 2.6) code like below:

import pexpect, multiprocessing

def login(h, u, p):
  ssh_new_key = ssh_change_key = 'abc'
  ssh = pexpect.spawn('ssh %s@%s' % (u, h))
  index = ssh.expect([ssh_change_key, ssh_new_key, 'password:'], timeout=5)

def worker():
    login('1.2.3.4', 'abc', 'abc')

if __name__ == '__main__':
  e_process = multiprocessing.Process(target=worker, args=[])
  e_process.start()
  e_process.join()

but runs failed, with this traceback:

Process Process-1:
Traceback (most recent call last):
  File "/usr/lib64/python2.6/multiprocessing/process.py", line 232, in _bootstrap
    self.run()
  File "/usr/lib64/python2.6/multiprocessing/process.py", line 88, in run
    self._target(*self._args, **self._kwargs)
  File "test.py", line 8, in worker
    login('1.2.3.4', 'abc', 'abc')
  File "test.py", line 4, in login
    ssh = pexpect.spawn('ssh %s@%s' % (u, h))
  File "/usr/lib/python2.6/site-packages/pexpect-3.3-py2.6.egg/pexpect/__init__.py", line 493, in __init__
    fd = sys.__stdin__.fileno()
ValueError: I/O operation on closed file

however pexpect 3.3 runs well in a none multiprocessing environment
And I test it on pexpect 2.4 (also with python 2.6), it runs well too.

@jquast

This comment has been minimized.

Member

jquast commented Jul 2, 2014

Ahh, I guess stdin is closed, as seen in https://docs.python.org/2/library/multiprocessing.html#all-platforms under section. I made this change, I'll revert it -- thanks.

@jquast jquast self-assigned this Jul 2, 2014

@jquast jquast added the bug label Jul 2, 2014

jquast added a commit that referenced this issue Jul 2, 2014

@fordguo

This comment has been minimized.

fordguo commented Aug 21, 2014

I count the same problem with celery :(

jquast added a commit that referenced this issue Aug 24, 2014

Closes issue #86 and issue #100
Fallback to using stdout, and, when both stdin
and stdout are *both* closed, catch ValueError
and use the same constants as when the attached
process is not a terminal.

takluyver added a commit that referenced this issue Sep 4, 2014

@takluyver

This comment has been minimized.

Member

takluyver commented Sep 4, 2014

Closed by #109.

@takluyver takluyver closed this Sep 4, 2014

timstaley added a commit to timstaley/drive-casa that referenced this issue Apr 15, 2015

timstaley added a commit to timstaley/autocrunch-ami that referenced this issue Apr 15, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment