Re: process and spinning slash
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: process and spinning slash

From: Alex Martelli <aleaxit@yahoo.com>
Date: Sun Oct 30 2005 - 17:21:29 CET

Fredrik Lundh <fredrik@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
Received on Mon Nov 21 01:06:04 2005