Is there a way to pause a process (running from an executable) so that it stops the cpu load while it's paused, and waits till it's unpaused to go on with its work? Possibly in python, or in some way accessible by python.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I just implemented this with signals in python something like this:
This will pause at the last line and call
do_something()
when it receives the signal USR1, for example through acommand.
This will only work in UNIX though.
There is a (almost) native way of doing this in Python, and it's quite simple :
In this snippet,
5
is the number of seconds you want to pause your program.By using psutil ( https://github.com/giampaolo/psutil ):
you are thinking of SIGTSTP -- the same signal that happens when you push
CTRL-Z
. This suspends the process until it gets SIGCONT.of course, some programs can just catch and ignore this signal, so it depends on the executable. however, if you can suspend and resume it manually, you can do it from a python program, too. use
os.kill()