running a python script in the background

Josiah Carlson jcarlson at uci.edu
Sat Oct 30 02:08:25 EDT 2004


arun.sivakumaran at gmail.com (Arun) wrote:
> the simulations totally in the background (the simulations run for a
> day or two, so basically I want to start them in background and log
> off).

> Now if I start the script in the background with "script.py &", it
> doesn't work. I figure the reason is the system() call spawns the
> simulator in the foreground.

> Is there a way I can make this all run in the background, while at the
> same time ensuring that only one instance of the simulator is running?

It sounds like you are running this on *nix.  The Python interpreter is
likely dying when you log-off due to a 'hangup' signal being called when
you log out.

What has worked for me in the past is to SSH to localhost, executing:
"nohup python script.py &" and disconnecting.  It should work running
from a local terminal (without SSH), but I can't guarantee it.

 - Josiah




More information about the Python-list mailing list