How to know that a second application has finished?

Chris Tavares christophertavares at earthlink.net
Wed Dec 19 00:53:32 EST 2001


"Enrique" <ecastro at cicei.ulpgc.es> wrote in message
news:3C1F6F21.C03A3ABC at cicei.ulpgc.es...
> Hi,
>    Let me put my question again, in a different and more
> general form. I have a Python program that launches a GUI
> application in a separate window via COM. I am using Python
> 2.1.1 with win32 extensions in MS-Windows (win95/98/NT)
>
> Is it possible to suspend the main Python program until the
> COM application has finished? (has been closed).
> I want to resume from that point onwards. How the main
> program gets information of the state of other applications
> launched from it?
>
> Thanks in advance
> Enrique Castro

It kind of depends on the app you're starting. Does it have some method to
tell the calling app that it's quitting?

The general way to do this under Win32 is to get the process handle somehow
(usually via a call to CreateProcess) and call WaitForSingleObject. You
could do some tricks to get the process handle another way, BUT this won't
work in your situation.

The problem is this: COM servers don't exit as long as there's an
outstanding reference to that server's objects. Now, consider this:

Client calls CoCreateInstance - er, win32com.Client.Dispatch, sorry :-)

Server is created

Client waits for server to exit

Server waits for final reference to go away before exitting

Boom, deadlock.

Seems to me your choices are:

1) Use CreateProcess to start the other app instead of creating a COM
server.

2) Modify the server so that it gives you an OnClosing event (or something
of the sort)

or, my favorite,

3) Modify the server's interface so that it has a
"DoYourThingAndDontReturnTillYoureDone" method. Then the client just calls
that, the server doesn't return until the user's done, and then you can
clean up and go away.

-Chris


-Chris






More information about the Python-list mailing list