471,046 Members | 1,316 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,046 software developers and data experts.

Python script running as Windows service: Clean shutdown


I'm trying to run a Python script as a Windows service with a defined
shutdown. The script (enigma-client.py) handles the communications with
the server in a distributed computing effort and calls a C program
(enigma.exe) to do the computations.

enigma.exe should save its current state when receiving SIGINT or SIGTERM.
This (obviously) works under Unix and also when running the script from the
Windows command line and terminating it with Ctrl-C.

I understand that for a clean shutdown of a Windows service one would
have to use the win32 extensions and have the working thread check
for the shutdown event in short intervals (<dd**********@online.de>).
This would leave me with these options:

a) Write enigma-client.py as a service. Write enigma.exe as a
service and have it poll regularly for shutdown events.

b) Have enigma.exe save its state regularly, use srvany.exe
and forget about a graceful shutdown.
I'm new to Windows services, so I'd be grateful for corrections or
better solutions. Here is relevant part of the code (The whole thing
is at http://www.bytereef.org/enigma-client.txt ):

""" main """
cmdline = 'enigma.exe -R 00trigr.naval 00bigr.naval 00ciphertext > NUL'
eclient = Eclient()

if len(sys.argv) != 3:

if os.path.isfile(LOCKFILE):
print "enigma-client: error: found lockfile %s. \n" \
"Check that no other enigma-client process is using this directory." \



while 1:
retval = os.system(cmdline) >> 8
if retval == 0:
eclient.submit_chunk(sys.argv[1], int(sys.argv[2]))
eclient.get_chunk(sys.argv[1], int(sys.argv[2]))
elif retval == 1:
eclient.get_chunk(sys.argv[1], int(sys.argv[2]))
"""./enigma has caught a signal"""

Stefan Krah

Break original Enigma messages: http://www.bytereef.org/m4_project.html
Jan 11 '06 #1
0 1730

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by David Fraser | last post: by
2 posts views Thread by Mr Newbie | last post: by
16 posts views Thread by diffuser78 | last post: by
reply views Thread by Kurt B. Kaiser | last post: by
1 post views Thread by Aspersieman | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.