472,951 Members | 2,233 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 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 2045

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: David Fraser | last post by:
Hi We are trying to debug a problem with services created using py2exe. It seems that these problems have arisen after services were installed and removed a few times. OK, first the actual...
by: EW | last post by:
I have a problem when using the python script found here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/360649 It is a script to remotely shutdown a windows computer. When I use it,...
by: Jonathan Heath | last post by:
Hi all, I have created an ASP script that enters data into an Access Database. My problem is that I'd like this script to run when the computer is shutdown or the user logs off. I think...
by: Mr Newbie | last post by:
I have an annoying teenager who wont go to bed because he is allways on his computer. I want to write a windows service which will shut down his computer at night and not allow this to be...
by: zxo102 | last post by:
Hi there, I have a python application (many python scripts) and I start the application like this python myServer.py start in window. It is running in dos window. Now I would like to put it...
by: diffuser78 | last post by:
I want to write a python program and call OS specific commands in it. So basically, instead of typing in on the command line argument I want to have it in a python program and let it do the action....
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 393 open (+15) / 3315 closed (+17) / 3708 total (+32) Bugs : 908 open (+22) / 5975 closed (+49) / 6883 total (+71) RFE : 223 open...
by: Aspersieman | last post by:
Hi All I have a windows service (attached file). I basically just calls another script every 60 seconds. I can install, start and stop this service as expected with: ParseMailboxService.py...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.