How to Check Python3 Process running on macOS background terminal? - python-3.x

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 ! :/)

Related

command runs fine as standalone but not with nohup

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 &

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

Bash Simulate User input for terminal gui program

I have been trying to automate the setup process for pi hole on a raspberry pi. I am relatively new to bash and am unable to figure out how to automate the setup process once the terminal gui for the program begins.
this is what I have so far
#!/bin/bash
pihole -r
echo "waited"
$SHELL
So I reiterate back to my question, how do I automate the task of choosing and entering the option in the terminal gui of the pihole program? Any help would be greatly appreciated.
There's already a script that should be able to do it for you ("Pi-hole Automated Install")
To execute it you'd do:
curl -L install.pi-hole.net | bash
unfortunately it's too big to post here, so you'll want to grab it
here:
↳ Github : Pi-hole Automated Install

Having problems running python script even when putty is closed

So basically, I have a bot I'm running, and I would like for it to keep running even when I exit putty.
I've tried using nohup python bot.py & but it still ends the python bot when I close the putty program. I've also tried using a run.sh file with /usr/bin/nohup bot.py & inside it. but it won't work :( is there something else I'm missing?
I have also made sure the run.sh is a executable as some other forums have suggested, and I still get can't open run
I'm kinda new to the linux terminal.
if you guys could help me out that would be awsome :)
You need to detach the terminal so that when you exit, it is still running. You can use screen or tmux or some other multiplexer.
Here is how to do with screen:
screen -S mybot -m -d /usr/bin/python /path/to/bot.py
-S give the session a name (this is useful if you want to attach later. screen -D -R mybot)
-m always create a new session
-d detach (launch the program, but then detach the terminal returning you to the prompt)

Resources