help in pexpect multiprocessing
harirammanohar159 at gmail.com
harirammanohar159 at gmail.com
Mon Nov 9 07:37:24 EST 2015
Hi,
I am using multiprocessing with pexpect, issue is whenever i call a function which is having expect(), its throwing error which is genuine as multiple threads are processing it same time (i/o prompt same time by multiple processes..so issues in picture...), so i want to use lock for that section alone to avoid it, but still fails in implementing it...can you help me
username = input('Enter your username: ')
password = getpass.getpass()
s = pxssh.pxssh()
s.login ('host','username','password')
s.sendline ('ps -ef|grep java')
s.prompt(timeout=1)
Try 1:
if condition == 'met':
np = len(list1)
p = multiprocessing.Pool(np)
p.map(stop, [(ds) for ds in list1])
def stop(ds):
s.sendline ('cd /usr')
if condition:
lock = threading.Lock()
lock.acquire()
s.expect('Enter username:')
s.sendline ('user')
s.expect('Enter password:*')
s.sendline('pass')
lock.release()
s.prompt(timeout=200)
print('stopped ds...')
Try 2:
if condition == 'met':
lock = Lock()
for ds in list1:
Process(target=stop, args=(ds,lock)).start()
def stop(ds,l):
s.sendline ('cd /usr')
if condition:
l.acquire()
s.expect('Enter username:')
s.sendline ('user')
s.expect('Enter password:*')
s.sendline('pass')
l.release()
s.prompt(timeout=200)
print('stopped ds...')
Both are giving me same trace..
pexpect.ExceptionPexpect: isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process?
Thanks in Advance
More information about the Python-list
mailing list