process and spinning slash

Alex Martelli aleaxit at yahoo.com
Sun Oct 30 11:21:29 EST 2005


Fredrik Lundh <fredrik at pythonware.com> wrote:

> Alex Martelli wrote:
> 
> > Have the spin function accept the pid argument and exit the loop if said
> > pid has terminated; to check the latter, e.g., os.kill(pid, 0) -- this
> > will raise an OSError if no process with that pid exists, so you can use
> > a try/except OSError: to catch that and break as appropriate.
> 
> or use the subprocess module instead of fork/exec, pass the Popen instance
> to spin, and use the poll() method to check if the process is still running.

Much more elegant than the lower-level approach I was sketching, of
course, if one can use Python 2.4 (one cannot always sensibly do that;
e.g., Mac OS X Tiger [the latest release] includes Python 2.3.5, so if
you want to write Mac applications in Python 2.3 packaging and
distributing them is trivial, but if you want to use Python 2.4 you need
to distribute that as well, or package it with your app and thus make it
way bigger... so, limiting oneself to 2.3 is a reasonable choice here).


Alex



More information about the Python-list mailing list