spawn() problem

Albert Hofkamp hat at se-46.wpa.wtb.tue.nl
Tue Jan 21 09:03:54 EST 2003


On Fri, 17 Jan 2003 11:04:50 -0700, bob <bvdpoel at kootenay.com> wrote:
> 
> I using a tkinter program to launch some console-type programs. Works 
> fine, almost.
> 
> I have a command something like:
> 
> 	PID = os.spawnlp(os.P_NOWAIT, myprog, myprog, f)
> 
> So, this now runs in the backgound. Fine.
> 
> I've got an 'abort' button which uses the PID to kill the spawned program:
> 
> 	os.kill(PlayPID, signal.SIGQUIT)
> 
> Again, no problem. Even if the program has already terminated.

Except when the program has terminated a long time ago, and in the mean
time the PID numbers have looped, and you happened to run a very important
other process that just happened to have the same PID assigned.

> But, there are some other clean up things I'd like to do only if the 
> program has not exited. So, what I need to do is to signal something 
> when the program terminates. And that part I can't figure out.

The newer Pythons have an atexit() like construct where you can perform
cleanup operations after the program ended, but before the OS cleans up.
That sounds like a hook where you can attach a function that kills the
playing process.

Otherwise, Tkinter quite likely drops out of the main loop call at the end
of your program. Rather than returning to the OS immediately, maybe you can
perform cleanup there.

Albert
-- 
Unlike popular belief, the .doc format is not an open publically available format.




More information about the Python-list mailing list