How to suspend a script?

Greg Ewing (using news.cis.dfn.de) wmwd2zz02 at sneakemail.com
Tue Feb 24 22:11:12 EST 2004


Ben Finney wrote:
> On Wed, 25 Feb 2004 11:29:07 +1100, Steve wrote:
> 
>>How can I send a python script a suspend signal?
> 
> You can send any signal to a process with the (poorly-named) 'kill'
> command.

Also it doesn't matter whether it's a Python program
or anything else -- the OS intercepts the SIGSTOP
or SIGTSTP signals and suspends the process until
it receives a SIGCONT signal.

Note that this will indiscriminately suspend the
process in the middle of whatever it happened to
be doing at the time. This could have bad effects
if e.g. the process is updating the database and
has part of it locked.

If that's a problem, you may need to use some other
signal and arrange for the Python code to catch
the signal and suspend itself when it's safe to
do so. It can do that using the pause() function
in the signal module.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list