bizet
bizet

Reputation: 53

pexpect runs failed when use multiprocessing

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 = 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 run well in a none multiprocessing environment, why?

Upvotes: 1

Views: 1312

Answers (1)

Paul Shucksmith
Paul Shucksmith

Reputation: 26

It appears to be a problem with pexpect version 3.3. In my experience, the issue does not arise with pexpect version 3.1 and 3.2 (tested with python 2.7).

Upvotes: 1

Related Questions