Re: how to kill subprocess when Python process is killed?

2009-08-07 Thread mark.v.we...@gmail.com
On Aug 7, 12:57 am, alex23 wuwe...@gmail.com wrote:
 On Aug 7, 3:42 pm, mark.v.we...@gmail.com mark.v.we...@gmail.com
 wrote:

  When I kill the main process (cntl-C) the subprocess keeps running.
  How do I kill the subprocess too? The subprocess is likely to run a
  long time.

 You can register functions to run when the Python process ends by
 using the atexit[1] module.

 The following has been tested  works under Python 2.6 on Windows XP:

     import atexit

     def cleanup():
         print 'stop thesubprocessin here'

     atexit.register(cleanup)

     while True:
         pass

 [1]:http://docs.python.org/library/atexit.html

Works perfectly. Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


how to kill subprocess when Python process is killed?

2009-08-06 Thread mark.v.we...@gmail.com
I am writing a Python program that launches a subprocess (using
Popen).
I am reading stdout of the subprocess, doing some filtering, and
writing to
stdout of the main process.

When I kill the main process (cntl-C) the subprocess keeps running.
How do I kill the subprocess too? The subprocess is likey to run a
long time.

Context:
I'm launching only one subprocess at a time, I'm filtering its stdout.
The user might decide to interrupt to try something else; the user
wants the process and all subprocesses to go away in response
to a cntl-C

I'm new to python; solution must be for Python 2.5 (windows) to help
me.

Any help and/or pointers appreciated.


-- 
http://mail.python.org/mailman/listinfo/python-list