Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Pablo Lucena Newsgroups: comp.lang.python Subject: Re: help in pexpect multiprocessing Date: Tue, 10 Nov 2015 07:42:02 -0500 Lines: 103 Message-ID: References: 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: 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>': 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98594 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 =3D pxssh.pxssh() =E2=80=8B =E2=80=8B s.login ('host','username','password') s.sendline ('ps -ef|grep java') s.prompt(timeout=3D1) s.sendline ('cd /usr') if condition: lock =3D threading.Lock() lock.acquire() s.expect('Enter username:') s.sendline ('user') s.expect('Enter password:*') s.sendline('pass') lock.release() s.prompt(timeout=3D200) print('stopped ds...') if condition =3D=3D 'met': np =3D len(list1) p =3D multiprocessing.Pool(np) p.map(stop, [(ds) for ds in list1]) On Mon, Nov 9, 2015 at 7:37 AM, 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 =3D input('Enter your username: ') > password =3D getpass.getpass() > > s =3D pxssh.pxssh() > s.login ('host','username','password') > s.sendline ('ps -ef|grep java') > s.prompt(timeout=3D1) > > Try 1: > > if condition =3D=3D 'met': > np =3D len(list1) > p =3D multiprocessing.Pool(np) > p.map(stop, [(ds) for ds in list1]) > > def stop(ds): > s.sendline ('cd /usr') > if condition: > lock =3D threading.Lock() > lock.acquire() > s.expect('Enter username:') > s.sendline ('user') > s.expect('Enter password:*') > s.sendline('pass') > lock.release() > s.prompt(timeout=3D200) > print('stopped ds...') > > Try 2: > > if condition =3D=3D 'met': > lock =3D Lock() > for ds in list1: > Process(target=3Dstop, args=3D(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=3D200) > 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 > --=20 *Pablo Lucena*