I'm trying to create a program that runs in the background but can be easily paused an unpaused. This can be done by starting another copy of prog.py and using pause flags. I can successfully pause and unpause my program this way. Using sig handlers I can output to stdout "Pausing program" "Resuming program"
I start the program to do work with a command like:
./prog.py -H foo -P bar -i 10
When I run the program as
./prog.py --pause 1
This causes a flag to be raised that calls
os.kill(%pid, signal.SIGSTOP)
everything pauses as it should but the first time (and ONLY the first time) I pause it I get this type of output to stdout:
[2]+ Stopped ./prog.py -H foo -P bar -i 10
I have tried to suppress it by setting sys.stdout = '/dev/null' but that didn't seem to do it. It's not the end of the world if I can't figure it out, i'm just a bit annoyed and really only want to see pause and resume in the parent program. Any ideas?
It's not python to print that line.
That line is printed by your shell (
bash
probably) when you suspend a job.So you cannot suppress from within python.
The bad news is that you cannot suppress printing of that information from bash either. See the answer of How to suppress Terminated message after killing in bash?