Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python hangs when executing a shell script that runs a process as a daemon

I am trying to use os.system (soon to be replaced with subprocess) to call a shell script (which runs a process as a daemon)

os.system('/path/to/shell_script.sh')

The shell script looks like:

nohup /path/to/program &

If I execute this shell script in my local environment, I have to hit enter before being returned to the console as the shell script is running a process as a daemon. If I do the above command in python, I also have to hit enter before being returned to the console.

However, if I do this in a python program, it just hangs forever.

How can I get the python program to resume execution after calling a shell script that runs a process as a daemon?

like image 428
Matthew Moisen Avatar asked Sep 12 '26 02:09

Matthew Moisen


1 Answers

From here -

Within a script, running a command in the background with an ampersand (&) may cause the script to hang until ENTER is hit. This seems to occur with commands that write to stdout.

You should try redirecting your output to some file (or null if you do not need it), maybe /dev/null , if you really do not need the output.

 nohup /path/to/program > /dev/null &
like image 165
Anand S Kumar Avatar answered Sep 14 '26 16:09

Anand S Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!