Launch script on Linux using Putty

Michael Hoffman cam.ac.uk at mh391.invalid
Mon Apr 2 14:34:30 EDT 2007


[Michael Hoffman]
>> 1. The easiest is to run nohup on your script in the background:
>>
>> $ nohup myscript.py > output.txt 2> error.txt &
>>
>> Then you can disconnect but your script will keep running. Try man nohup
>>   for more information.
>>
>> 2. Use GNU screen on your remote terminal, and detach the screen instead
>> of logging off.
>>
>> 3. Set up your script to fork as a daemon. Google for ["python cookbook"
>> fork daemon] to find a few recipes for this.

[Ulysse]
> 1. nohup seems not to be installed on my "reduced linux distribution".
> It's a OpenWrt tunning on my WRT54GL Broadband router.

If you are running bash, you can do this:

$ myscript.py &
[1] 30834

$ disown %1

> 2. I have looked for the way I can "detach the screen" with Putty but
> I've not found (May be you can precise ?)

Google for GNU screen. But it probably won't be installed either, if 
nohup isn't.

> 3. The "fork daemon" script found on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731
> seems to be as huge as my own script and little bit hard to undestand.

OK, another alternative is to simulate nohup yourself, using the signal 
module. You might want to read the docs and search the cookbook for 
examples of its use. I think it would be something like:

import signal

signal.signal(signal.SIGHUP, signal.SIG_IGN)
-- 
Michael Hoffman



More information about the Python-list mailing list