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


Groups > comp.lang.python > #2313

Behaviour of subprocess.Popen, ssh and nohup I don't understand

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!news-transit.tcx.org.uk!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <renting@astron.nl>
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; 'else:': 0.03; 'loop,': 0.07; 'python': 0.07; 'command.': 0.09; 'executed': 0.09; 'none.': 0.09; 'received:192.87': 0.09; 'run.': 0.09; 'ssh': 0.09; 'subject:don': 0.09; 'subprocess': 0.09; 'sys,': 0.09; 'written': 0.12; 'output': 0.12; 'password.': 0.14; 'starts': 0.15; '--version': 0.16; '2.5.2': 0.16; 'from:addr:astron.nl': 0.16; 'keystrokes': 0.16; 'received:192.87.1': 0.16; 'received:nfra.nl': 0.16; 'stdin=none,': 0.16; 'subject:ssh': 0.16; 'subprocess,': 0.16; 'subject:skip:s 10': 0.16; 'ignore': 0.16; 'thanks,': 0.17; 'input': 0.18; 'combination': 0.19; 'command': 0.19; 'seems': 0.21; 'maybe': 0.21; '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; 'load': 0.28; 'problem': 0.29; 'exit': 0.29; 'this.': 0.30; 'second': 0.31; 'random': 0.31; 'import': 0.32; 'to:addr:python-list': 0.32; "i've": 0.33; 'option': 0.33; 'someone': 0.33; 'test': 0.33; 'received:192': 0.34; 'actually': 0.34; 'there': 0.35; 'couple': 0.35; 'print': 0.35; 'running': 0.36; 'think': 0.36; 'none': 0.36; 'charset:us-ascii': 0.36; 'background': 0.37; 'run': 0.37; 'despite': 0.38; 'but': 0.38; 'happens': 0.38; 'log': 0.38; '[1]': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'header:Mime- Version:1': 0.39; 'solution': 0.40; 'would': 0.40; "it's": 0.40; 'waiting': 0.61; 'header:Message-Id:1': 0.62; 'bring': 0.62; 'here': 0.65; 'interrupted': 0.68; '0.00': 0.91; 'suspend': 0.91
X-Mailer Novell GroupWise Internet Agent 8.0.2
Date Fri, 01 Apr 2011 01:01:19 +0200
From "Adriaan Renting" <renting@astron.nl>
To <python-list@python.org>
Subject Behaviour of subprocess.Popen, ssh and nohup I don't understand
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
Content-Disposition inline
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.52.1301613744.2990.python-list@python.org> (permalink)
Lines 82
NNTP-Posting-Host 82.94.164.166
X-Trace 1301613744 news.xs4all.nl 81479 [::ffff:82.94.164.166]:56602
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:2313

Show key headers only | View raw


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):
  command = ["ssh", "-T", "localhost", "uptime"]
  comm = subprocess.Popen(command, shell=False, stdin=None,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
  print  '1'
  if comm.returncode:
    print "error: %i" % (comm.return_code)
  else:
    print  '2'
    (output, output2) = comm.communicate(input=None)
    print output
    print output2 
  print  '3'
  time.sleep(3)

(renting)myhost> python --version
Python 2.5.2

(renting)myhost> nohup ./test.py -O2 &
[1] 15679

(renting)myhost> 1
2
 22:40:30 up 24 days,  7:32,  1 user,  load average: 0.00, 0.00, 0.00

None
3
1
2

[1]  + Suspended (tty input)         ./test.py -O2
(renting)myhost> fg
./test.py -O2

 22:40:35 up 24 days,  7:32,  1 user,  load average: 0.00, 0.00, 0.00

None
3
1
2
 22:40:56 up 24 days,  7:32,  1 user,  load 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,

thanks,

Adriaan Renting

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


Thread

Behaviour of subprocess.Popen, ssh and nohup I don't understand "Adriaan Renting" <renting@astron.nl> - 2011-04-01 01:01 +0200

csiph-web