Re: process and spinning slash



Fredrik Lundh <fredrik@xxxxxxxxxxxxxx> 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
.



Relevant Pages

  • Re: A design problem
    ... So I just recently started picking up Python, ... I'd use pid instead ... I feel like Python's lists or dictionaries ...
    (comp.lang.python)
  • Re: "no variable or argument declarations are necessary."
    ... > aleax@xxxxxxxxxxxxxxxx (Alex Martelli) writes: ... but why isn't it built into Python? ... but Active Python (from ... "core" (mostly the kernel, in Linux's case; ...
    (comp.lang.python)
  • Re: Expanding Python as a macro language
    ... Alex Martelli and Mike Meyer. ... I hoped to have found it in Python, ... > is fake, through a special flag if it cares to check for it, ... My answer is the same as that given to Michael about low level ...
    (comp.lang.python)
  • Re: a python book hint
    ... Alex Martelli wrote: ... >safari.oreily.com, subscribe, and read Python in a Nutshell (and/or ... Amazon recently added a new feature that gives yet another ...
    (comp.lang.python)
  • Re: How do you execute an OS X application (bundle) from Python?
    ... >> For example, in Python in a Nutshell, Alex Martelli shows how you can ... Python like on the Windows version -- to *WAIT* until the app is done ... TextEdit is done editing that document? ... "Spawning an external editor and waiting until the user is done using it ...
    (comp.lang.python)