multiprocessing & more

Adam Skutt askutt at gmail.com
Mon Feb 14 12:53:06 CET 2011


On Feb 14, 5:33 am, Andrea Crotti <andrea.crott... at gmail.com> wrote:
 > Well the other possibility that I had in mind was to spawn the very
> long process in an asynchronous way, but then I still have the
> problem to notify the rest of the program that the simulation is over.
>
> Is there a way to have an asynchronous program that also notifies when
> it's over easily?
>

Several, again, what's best depends on what you're doing:
* If you can modify the application, you can have it modify that
shared Value before it exits.
* On UNIX, you can do a non-blocking waitpid() call to determine when
the process exited.  The catch is that you can only do this from an
actual parent process, so you'd have to reconstruct the way you spawn
processes. Plus, if you need the stdout/stderr from the process you
then must also consume the I/O in an non-blocking fashion, or dedicate
a thread solely to consuming the I/O.  It's possible to pull similar
trickery in Windows, however I don't think the standard Python library
makes it convenient (the right Win32 call is GetExitCodeProcess, given
a legitimate Win32 process HANDLE).
* You have it write something to stdout/stderr and key off of that.

Those (or slight variants on them) are the common ways.

Adam



More information about the Python-list mailing list