Porcess control on win32
Mark Hammond
mhammond at skippinet.com.au
Sun Mar 10 22:10:38 EST 2002
Ben C wrote:
> Hi,
>
> I am trying to achieve this scenario on a Win32 machine ...
>
> a. create a lot of new processes (ie. open application 'x' a number of
> times with different args)
>
> b. each time 1 of the processes exits ... do something
>
> I have looked at using somehting like this
>
> ...
>
> project_lst = ['application1', 'application2', 'application3', etc]
>
> for application in project_lst:
>
> process, thread, pid, tid = win32process.CreateProcess(
> None,
> application ,
> None,
> None,
> 0,
> win32process.NORMAL_PRIORITY_CLASS,
> None,
> None,
> win32process.STARTUPINFO())
>
> win32event.WaitForSingleObject(process, win32event.INFINITE)
>
> print 'Application %s Has Just Exited) % (application,)
> ...
>
> The problem with this structure is it spawns each application in
> sequence ... how can I modify this sructure to spawn all applications
> simultaneously and still have the print statement executed only when
> one of the projects exits?
Something like:
processes = []
for app in project_lst:
p, t, pid, tid = win32process.CreateProcess(...)
processes.append(p)
while processes:
# Wait for one, then remove that one from the list.
rc = win32event.WaitForMultipleObjects(processes, INFINITE, 0)
offset = rc - win32con.WAIT_OBJECT_0
del processes[offset]
Mark.
More information about the Python-list
mailing list