Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98871

Re: help in pexpect multiprocessing

X-Received by 10.66.240.206 with SMTP id wc14mr31909555pac.16.1447674028057; Mon, 16 Nov 2015 03:40:28 -0800 (PST)
X-Received by 10.50.122.103 with SMTP id lr7mr274306igb.10.1447674028023; Mon, 16 Nov 2015 03:40:28 -0800 (PST)
Path csiph.com!xmission!news.glorb.com!i2no3896797igv.0!news-out.google.com!l1ni6180igd.0!nntp.google.com!i2no3599584igv.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Mon, 16 Nov 2015 03:40:27 -0800 (PST)
In-Reply-To <c0f3d85c-d801-4106-9e1c-a84a2c077a4d@googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=151.151.16.16; posting-account=1SpZ5woAAAA9asrWwzRpL93v3FfBemIc
NNTP-Posting-Host 151.151.16.16
References <c0f3d85c-d801-4106-9e1c-a84a2c077a4d@googlegroups.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <73aaf275-3d2c-4148-8a43-204bd2cd128e@googlegroups.com> (permalink)
Subject Re: help in pexpect multiprocessing
From harirammanohar159@gmail.com
Injection-Date Mon, 16 Nov 2015 11:40:28 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:98871

Show key headers only | View raw


On Monday, 9 November 2015 18:07:36 UTC+5:30, hariramm...@gmail.com  wrote:
> 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

Hey Lucena,

Thank you for suggestion, yeah process queues doing the samething, creating new sesssion for each process and executing simulatenously.. requirement is served..

but still i want to tackle the situation with locks, but not able to as throwing the below error.

pexpect.ExceptionPexpect: isalive() encountered condition where "terminated" is 0, but there was no child process. Did someone else call waitpid() on our process? 

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

help in pexpect multiprocessing harirammanohar159@gmail.com - 2015-11-09 04:37 -0800
  Re: help in pexpect multiprocessing harirammanohar159@gmail.com - 2015-11-10 02:16 -0800
  Re: help in pexpect multiprocessing harirammanohar159@gmail.com - 2015-11-10 04:22 -0800
  Re: help in pexpect multiprocessing Pablo Lucena <plucena24@gmail.com> - 2015-11-10 07:42 -0500
  Re: help in pexpect multiprocessing harirammanohar159@gmail.com - 2015-11-16 03:40 -0800

csiph-web