Paul Diaconescu wrote: > > fredagen den 4 juli 2003 kl 04.12 skrev Graham Fawcett: > >> >> I'm attaching a sample service launcher. I'm embarrassed to post it, >> it's not an example of the Right and Proper Way to run a service, but >> it ought to do the trick until someone posts a better one! I use it to >> run a number of Medusa-based services with no trouble. >> >> Basically, starting the service just launches your server script in a >> new process, and stopping the service kills that process. Inefficient, >> perhaps, but it saves having to deal with both win32 and asyncore >> event loops in the same process. >> > > Does signal.signal work with this? I need to close the databases properly. > No. Last time I checked, signals only worked on Unix. And the win32process.TerminateProcess is a hard kill, i.e. any atexit functions you have registered will not be called. As far as I know, executing a soft kill of another process is currently beyond the reach of the win32all extensions. I just looked at Zope, and how it runs Medusa as an NT service. Surprisingly (to me, anyway), it uses the same CreateProcess/TerminateProcess approach. So there's no hope for you there. You could always google for 'win32serviceutil.ServiceFramework' and 'medusa' and see what turns up. But here are some other ideas. You could use a semaphore approach: a flag, external to both processes, to signal the change of state. Here's one simple way to do it: in the SvcStop method (which is run when the service is asked to stop), create a file in your app directory, named (for example), SHUTDOWN. Then have the service wait indefinitely while this file exists. As soon as it no longer exists, run the TerminateProcess command, and finish as usual. Meanwhile, in your 'backend' thread, check occasionally for the creation of the SHUTDOWN file. When it exists, that's your signal to close database connections. Close them, and then delete the SHUTDOWN file. Then the service can TerminateProcess, and you're done. If that's too medieval for you, you could open a pipe (via win32pipe) between the two processes, and send the database-shutdown signal that way. (If you don't own a copy of Mark Hammond's "Python Programming on Win32", it's definitely worth picking up if you are venturing into services, pipes and other Windows esoterica. Then again, Mark has been very gracious about sharing his expertise for free on comp.lang.python.) -- Graham