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


Groups > comp.lang.python > #98594

Re: help in pexpect multiprocessing

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Pablo Lucena <plucena24@gmail.com>
Newsgroups comp.lang.python
Subject Re: help in pexpect multiprocessing
Date Tue, 10 Nov 2015 07:42:02 -0500
Lines 103
Message-ID <mailman.208.1447159325.16136.python-list@python.org> (permalink)
References <c0f3d85c-d801-4106-9e1c-a84a2c077a4d@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de bBCBbiJIUGNSqVYtxo6DHQWwE/MU/hNNw3ZhPCF0urpg==
Return-Path <plucena24@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'socket': 0.07; 'subject:help': 0.07; 'cc:addr:python-list': 0.09; 'command.': 0.09; 'executes': 0.09; 'subject:skip:m 10': 0.09; 'advance': 0.10; 'def': 0.13; 'received:io': 0.16; 'received:psf.io': 0.16; 'threads': 0.16; 'wrote:': 0.16; 'implementing': 0.18; 'email addr:gmail.com&gt;': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'function,': 0.22; 'pass': 0.22; 'cc:no real name:2**0': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'error': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'url:mailman': 0.30; 'code': 0.30; 'problem': 0.33; 'url:python': 0.33; 'lock': 0.33; 'username': 0.33; 'open': 0.33; 'url:listinfo': 0.34; 'server': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'skip:( 30': 0.35; 'nov': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'alone': 0.36; 'child': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:209': 0.38; 'skip:p 20': 0.38; 'someone': 0.38; 'hi,': 0.38; 'url:mail': 0.40; 'where': 0.40; 'still': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'avoid': 0.61; 'genuine': 0.63; 'our': 0.64; 'skip:\xc2 10': 0.67; 'prompt': 0.79; 'pablo': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=OUgYJjn1QOeIJ1boZsm2qCmckawxd/n7UPcow+YD7NA=; b=NuCkRvDITGXFDBXWmzqlwiETuDZdFaqb9GihuOgQf0XsbQzEZnZOCbu6XmA49tGxQo pwXLqO/u8QGJQWt+oNuRai0e/jfm0poW3Lt5Ulb+LrIfTkij9GXslAtkzvpJnVfa+UUD MJc7tycAIGeAffOFD9PF4uXeMpd6u2yORYfMM53Lg1dBgyHMwfg9xO9lNZc5RhMKVlCO 7iFS5vALo/q0MSarC3wpusRklwCZo+Ecd56wZS6k21XMnpPP4ryxPBUOLMQbeTx67HRU W9Dqjc5xLvFzJbYi5HfHRKkqlt/c38elAoFMZRihypFKfssGYdNCOt2O+75y93h/aGmh pj3g==
X-Received by 10.107.31.66 with SMTP id f63mr4007564iof.105.1447159322549; Tue, 10 Nov 2015 04:42:02 -0800 (PST)
In-Reply-To <c0f3d85c-d801-4106-9e1c-a84a2c077a4d@googlegroups.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.20+
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:98594

Show key headers only | View raw


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*

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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