Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Behaviour of subprocess.Popen, ssh and nohup I don't understand

Reply
Thread Tools

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

 
 
Kushal Kumaran
Guest
Posts: n/a
 
      04-01-2011
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):
> Â*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,
>


What operating system is this? Try with stdin=open(os.devnull, 'rb')
to the Popen call instead. Also, this seems to be similar:
http://stackoverflow.com/questions/1...din-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.

--
regards,
kushal
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Behaviour of subprocess.Popen, ssh and nohup I don'tunderstand Adriaan Renting Python 1 04-06-2011 11:35 PM
Behaviour of subprocess.Popen, ssh and nohup I don'tunderstand Adriaan Renting Python 0 03-31-2011 11:01 PM
Re: nohup and os.system Cameron Simpson Python 0 03-12-2009 05:37 AM
nohup and os.system Gideon Python 0 03-12-2009 04:05 AM
get pid of a nohup command in Python g.willgoose@telluricresearch.com Python 1 02-13-2007 05:52 AM



Advertisments