Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'background.': 0.03; 'loop,': 0.07; 'python': 0.07; 'command.': 0.09; 'executed': 0.09; 'none.': 0.09; 'run.': 0.09; 'ssh': 0.09; 'subject:don': 0.09; 'subprocess': 0.09; 'sys,': 0.09; 'written': 0.12; 'output': 0.12; 'am,': 0.14; 'password.': 0.14; 'received:74.125.82.44': 0.14; 'received:mail-ww0-f44.google.com': 0.14; 'wrote:': 0.14; 'starts': 0.15; "'rb')": 0.16; '--version': 0.16; '2.5.2': 0.16; 'keystrokes': 0.16; 'stdin,': 0.16; 'stdin=none,': 0.16; 'subject:ssh': 0.16; 'subprocess,': 0.16; '\xc2\xa0if': 0.16; 'subject:skip:s 10': 0.16; 'ignore': 0.16; 'this?': 0.18; 'input': 0.18; 'combination': 0.19; 'command': 0.19; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'seems': 0.21; 'maybe': 0.21; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'trying': 0.23; 'keys': 0.23; 'pair': 0.23; 'welcome.': 0.23; "what's": 0.24; 'skip:# 10': 0.25; 'script': 0.26; "i'm": 0.26; 'times.': 0.26; 'tried': 0.27; 'sender:addr:gmail.com': 0.27; 'message-id:@mail.gmail.com': 0.28; 'problem': 0.29; 'fri,': 0.29; 'exit': 0.29; 'instead.': 0.29; 'operating': 0.30; 'this.': 0.30; 'cc:addr:python.org': 0.31; 'second': 0.31; 'random': 0.31; 'import': 0.32; "i've": 0.33; 'option': 0.33; 'someone': 0.33; 'test': 0.33; 'actually': 0.34; 'got': 0.34; 'there': 0.35; 'couple': 0.35; 'running': 0.36; 'think': 0.36; 'none': 0.36; 'background': 0.37; 'run': 0.37; 'apr': 0.38; 'despite': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'happens': 0.38; 'log': 0.38; '[1]': 0.39; 'though,': 0.39; 'solution': 0.40; 'would': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'waiting': 0.61; 'bring': 0.62; '2011': 0.62; 'here': 0.65; 'interrupted': 0.68; 'skip:\xc2 10': 0.83; 'mechanism.': 0.84; 'suspended.': 0.84; '0.00': 0.91; 'suspend': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:from :date:x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=IiwK7VeonGDfG4cu8QwmkWpRRLuN45phHcjz+BCP//g=; b=VRSZSWUZTQxYF7AMBKasH/D7c+Zo9fo543gH12fMhuVzGmOSovd0rgFHM5S7agMvL+ tlb5VJX/6Nm7JEXEwxbLoeqtzIXG0cAAHPmqT7r8opSe3bhkmMwtYaeZvml754/4ojO6 /mljuVqXvmWzGSiLGswls4ljbdGyzhvAYSxaM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; b=cWkz0iVZBqVeXJMJjgzuEW5uzjuA6im+nLo8+OpMBT8yvSFUrX5Ogym16OJPprBBRu OqhyjnhmC6pDgmJykg4aq2Ixa7SMs2cT2QKv1rlDRDtoW/D59zMxyvu0/lhFEJKyr91o 2OVj4sTbZxs3adQZlrw/sBrLnti9SjzGYVESo= MIME-Version: 1.0 Sender: kushal.kumaran@gmail.com In-Reply-To: <4D9523EF0200001B00016CE4@smtp.nfra.nl> References: <4D9523EF0200001B00016CE4@smtp.nfra.nl> From: Kushal Kumaran Date: Fri, 1 Apr 2011 11:03:31 +0530 X-Google-Sender-Auth: PWM6NQMclSzgEZtcYxof_EZ6tUk Subject: Re: Behaviour of subprocess.Popen, ssh and nohup I don't understand To: Adriaan Renting Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 96 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1301636033 news.xs4all.nl 41113 [::ffff:82.94.164.166]:60247 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:2334 On Fri, Apr 1, 2011 at 4:31 AM, Adriaan Renting wrote: > L.S. > > I have a problem that a background process that I'm trying to start with > subprocess.Popen gets interrupted and starts waiting for input no matter > what I try to do to have it continue to run. It happens when I run it > with nohup in the background. > I've tried to find a solution searching the internet, but found none. > I've written a small test script that reproduces the problem and hope > maybe here there is someone who can tell me what's going wrong. Any > suggestions are welcome. > > (renting)myhost> cat test.py > #!/usr/bin/python > # script to test subprocess problem > import subprocess, sys, time > > for f in range(3): > =C2=A0command =3D ["ssh", "-T", "localhost", "uptime"] > =C2=A0comm =3D subprocess.Popen(command, shell=3DFalse, stdin=3DNone, > stdout=3Dsubprocess.PIPE, stderr=3Dsubprocess.STDOUT, close_fds=3DTrue) > =C2=A0print =C2=A0'1' > =C2=A0if comm.returncode: > =C2=A0 =C2=A0print "error: %i" % (comm.return_code) > =C2=A0else: > =C2=A0 =C2=A0print =C2=A0'2' > =C2=A0 =C2=A0(output, output2) =3D comm.communicate(input=3DNone) > =C2=A0 =C2=A0print output > =C2=A0 =C2=A0print output2 > =C2=A0print =C2=A0'3' > =C2=A0time.sleep(3) > > (renting)myhost> python --version > Python 2.5.2 > > (renting)myhost> nohup ./test.py -O2 & > [1] 15679 > > (renting)myhost> 1 > 2 > =C2=A022:40:30 up 24 days, =C2=A07:32, =C2=A01 user, =C2=A0load average: = 0.00, 0.00, 0.00 > > None > 3 > 1 > 2 > > [1] =C2=A0+ Suspended (tty input) =C2=A0 =C2=A0 =C2=A0 =C2=A0 ./test.py -= O2 > (renting)myhost> fg > ./test.py -O2 > > =C2=A022:40:35 up 24 days, =C2=A07:32, =C2=A01 user, =C2=A0load average: = 0.00, 0.00, 0.00 > > None > 3 > 1 > 2 > =C2=A022:40:56 up 24 days, =C2=A07:32, =C2=A01 user, =C2=A0load average: = 0.00, 0.00, 0.00 > > None > 3 > > (renting)myhost> > > Now as you can see, it suspends on the second time through the for loop, > until I bring it to the foreground and hit . > What you don't see, is that I make it do this by pushing the arrow keys > a couple of times. The same happens when I would exit the shell, despite > it running with nohup. > I don't need to exit to make it suspend, any combination of a few random > keystrokes makes it do this. It seems depending on the timing though, > during the sleep(3) it seems to ignore me, only when subprocess is > actually running will it suspend if I generate keystrokes. > If the ssh command is executed without -T option it suspends directly, > so I think it's related to the ssh command. I log in with a > public/private key pair to avoid having to enter a password. > > Any suggestions are welcome, > What operating system is this? Try with stdin=3Dopen(os.devnull, 'rb') to the Popen call instead. Also, this seems to be similar: http://stackoverflow.com/questions/1365653/calling-fgets-on-popen-of-ssh-is= -flushing-the-beginning-of-stdin-of-the-cal The "Suspended (tty input)" message means that a background process tried to read from stdin, so got suspended. This is part of the job control mechanism. --=20 regards, kushal