command runs fine as standalone but not with nohup - python-3.x

I have a python script I am trying to run using nohup.
This script runs perfectly with:
python3 script.py
But when run as:
nohup python3 script.py &
It gets stuck.
This script uses python multiprocessing
and gets stuck at
mp.Pool(mp.cpu_count())

Solved the problem.
One of the first things to check is, that if your python script is running.
If it is, the problem is because of buffering.
Run your command as:
nohup python3 -u script.py &

Related

When I try execute a shell script from within a shell script via a `#reboot` cron it does not run correctly, only works correctly executing in CML

When I try execute a shell script from within a shell script it works when executing in terminal manually. However, when executing it via a #reboot cron via sudo crontab -e on Raspberry Pi OS it runs everything apart from sh /home/pi/script.sh within the shell script.
My shell script:
#!/bin/sh
clear
sleep 5
python /home/pi/Desktop/Relay-Script-On.py
sleep 3
sh /home/pi/script.sh
sleep 5
python /home/pi/Desktop/Relay-Script-Off.py
sleep 3
I have made the other shell file executable using sudo chmod +x
Note I am still new to shell (apologies if there is an obvious error here).

How to Check Python3 Process running on macOS background terminal?

I'm running one python script using : nohup - python3 name.py >/dev/null & - to run one script in the background of my terminal. However would like to know best command to see a list of just python3 process running. i tried ps -xal|grep python3 (what i use on Linux) but was not working.
Thanks a lot ! :/)

nohup stops the process as soon as I press enter

I'm trying to run a script, say script.py that does not take any input from the terminal in the background using nohup by
nohup python3 script.py &
This command worked perfectly the last time I used it (and the script kept running for days!), but some error interrupted the process and it stopped. Eventually, nohup.out contained no error. (Is it supposed to?)
Now, I'm trying to run the script again, but am failing to do so. I use the same command, and then open the running processes using top but I get:
[2]- Stopped nohup python3 script.py
[3]+ Stopped nohup python3 script.py
I am failing to understand why is this happening now. Any help is appreciated!
P.S: The script runs perfectly without nohup.

How to watch python script which runs in background?

Im running python script in background on ubuntu linux with this command:
python script.py &
When Im closing terminal, its run on background
But how I can watch what script.py output, when opening terminal again?
There is many options for monitor the script in background.
First, run Screen command if you would like to disconnect the terminal. If you disconnect your terminal your script process will be an exit.
$ screen
$ python script.py &
Disconnect your terminal
$ screen -ls
Copy the PID and run the below command
$ screen -r PID
You are able to see your script output.
Several Options:
Use a tool like tmux
Use tail -f on the log file
Direct stdout to a file and use tail -f on it
python script.py > /tmp/logfile &
then later:
tail -f /tmp/logfile
Use screen to run your python script

jobs find nothing after nohup a script

I made a python script running on background:
nohup python app.py &
then close the terminal, a few days later, I want to see this job, so I run
jobs
there list no jobs, but I'm sure the script app.py is still running.
jobs will only give you a list of process running under the session group of the bash shell. nohup processes run in their own session group. There are a number of simple commands you can run to check if your nohup'd process is still running, the simplest being lsof | grep nohup (this command may take a few seconds to run)

Resources