Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98516 > unrolled thread
| Started by | harirammanohar159@gmail.com |
|---|---|
| First post | 2015-11-09 04:37 -0800 |
| Last post | 2015-11-16 03:40 -0800 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.lang.python
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
| From | harirammanohar159@gmail.com |
|---|---|
| Date | 2015-11-09 04:37 -0800 |
| Subject | help in pexpect multiprocessing |
| Message-ID | <c0f3d85c-d801-4106-9e1c-a84a2c077a4d@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | harirammanohar159@gmail.com |
|---|---|
| Date | 2015-11-10 02:16 -0800 |
| Message-ID | <c6e1a6a5-e7fb-4692-a47e-1da04043b11e@googlegroups.com> |
| In reply to | #98516 |
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
Hi,
can any one check it out
[toc] | [prev] | [next] | [standalone]
| From | harirammanohar159@gmail.com |
|---|---|
| Date | 2015-11-10 04:22 -0800 |
| Message-ID | <b92b602e-2a46-4c44-837f-9b7a97e7c28c@googlegroups.com> |
| In reply to | #98516 |
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
Hi,
I am able to manage it by using process queues, thank you
[toc] | [prev] | [next] | [standalone]
| From | Pablo Lucena <plucena24@gmail.com> |
|---|---|
| Date | 2015-11-10 07:42 -0500 |
| Message-ID | <mailman.208.1447159325.16136.python-list@python.org> |
| In reply to | #98516 |
I think the problem is that you cannot pass around an open socket via
pickle. Whats the error message you are getting?
Try adding the session establishment code to the stop function, so that
each new process opens a session to the server and executes the command.
def stop(ds):
s = pxssh.pxssh()
s.login ('host','username','password')
s.sendline ('ps -ef|grep java')
s.prompt(timeout=1)
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...')
if condition == 'met':
np = len(list1)
p = multiprocessing.Pool(np)
p.map(stop, [(ds) for ds in list1])
On Mon, Nov 9, 2015 at 7:37 AM, <harirammanohar159@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
> --
> https://mail.python.org/mailman/listinfo/python-list
>
--
*Pablo Lucena*
[toc] | [prev] | [next] | [standalone]
| From | harirammanohar159@gmail.com |
|---|---|
| Date | 2015-11-16 03:40 -0800 |
| Message-ID | <73aaf275-3d2c-4148-8a43-204bd2cd128e@googlegroups.com> |
| In reply to | #98516 |
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?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web