473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

stopping a python windows service

DK
i was able to successfully create a windows service using py2exe. it
polls a website periodically and logs it to a file. this is done using
a function that does an infinite loop with periodic "sleeps".

my question is...

what's the best way to stop this service gracefully?

when try to stop it from the services applet from control panel, it
takes forever and then gives me an error.

currently, the only way i am able to stop it is using the task manager
and killing the process.

Aug 16 '05 #1
6 5053
DK wrote:
i was able to successfully create a windows service using py2exe. it
polls a website periodically and logs it to a file. this is done using
a function that does an infinite loop with periodic "sleeps".

my question is...

what's the best way to stop this service gracefully?

when try to stop it from the services applet from control panel, it
takes forever and then gives me an error.

currently, the only way i am able to stop it is using the task manager
and killing the process.


Windows services generally use two threads: one to do the work and one to
listen for messages from the
whatever-the-component-is-called-to-control-services.
When the message thread received a 'stop' message, it should inform the
worker thread to shut down, e.g. using threading.Event. So your worker
should regularily check for the shutdown event, e.g.:

while not shutdownEvent.isset():
pollWebsite()

for i in xrange(1800):
if shutdownEvent.isset():
break
time.sleep(1)

But if you get the 'stop' message while the worker thread is in
pollWebsite() and the webserver is sloooow, you'll still have a significant
delay... To avoid this, you would need a http client based on select() that
allows you to check shutdownEvent.isset() at certain intervals - instead of
urlopen which just blocks.
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Aug 16 '05 #2
Here are 2 recipes from the online Python Cookbook. I've used this one
very successfully:
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/115875>.

This one seems simpler:
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/59872>

Grig

Aug 16 '05 #3
Hi !

Use SC.exe (windows-XP) (with popen ?)
For help : sc /?
You can, also, try :
qprocess /?
tasklist /?
taskkill /?
etc.

@-salutations

Michel Claveau

Aug 16 '05 #4
DK
I may have taken your code example too literally. I tried putting in
the check for 'shutdownEvent.isset()' but it's failing at run time.
It's looking for a global variable, I guess.

Do I have to register these threads somehow in the beginning?

I'm somewhat new to Python so please be patient...

Aug 17 '05 #5
On 17 Aug 2005 06:20:46 -0700, "DK" <pr*****@gmail.com> declaimed the
following in comp.lang.python:
I may have taken your code example too literally. I tried putting in
the check for 'shutdownEvent.isset()' but it's failing at run time.
It's looking for a global variable, I guess.
"shutdownEvent" is an event instance created using the threading
module.
Do I have to register these threads somehow in the beginning?
You'll have to create an Event object, a worker thread, and perhaps
leave the main thread as the monitor for system shutdown events.
I'm somewhat new to Python so please be patient...
Why do I find it discomforting that people new to the language keep
wanting to do deep OS specific actions in their first week?

{Granted, my first program was a rudimentary "sendmail" for my Amiga,
using ARexx scripts from the email client to queue messages into a temp
directory, and waking up, if needed, the Python program to parse the
to:, cc:, and bcc: headers, handshaking with the ISP's outgoing daemon
-- but everything I wrote was native Python; no OS specific code.
I needed to do this as the downloadable "sendmails" had major flaws:
the first one created a message file for each recipient, and would get
stuck if one of the recipient addresses wasn't receiving (this was back
in the days before ISPs locked port 25 passthrough); the second relayed
via the ISP -- but did not handshake the cc/bcc addresses, so such never
received the mail.}
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Aug 17 '05 #6
DK wrote:
I may have taken your code example too literally. I tried putting in
the check for 'shutdownEvent.isset()' but it's failing at run time.
It's looking for a global variable, I guess.


Or perhaps "it" is just looking for correct capitalization, since Python
is case sensitive. Try shutdownEvent.isSet() instead.

-Peter
Aug 18 '05 #7

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

Similar topics

5
by: CG | last post by:
Hi I have developed a Windows Service When I try to start the Service it tells me that it cannot start as there may not be any work to do When I comment out below line of code in my OnStart...
0
by: Daniel O'Brien | last post by:
Hi - any help with this would be greatly appreicated - it has already had me confused for a good few hours! I am using Visual Studio 2003 and the .NET framework 1.1. I have a C# Windows...
4
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group :...
0
by: GTS | last post by:
Hi, I have created my application to run as windows service. It is developed using VC++ on Windows 2000 platform. It is working fine with Windows 2000. But I am seeing problems in Windows 2003...
7
by: Gene | last post by:
I have a Windows Service (VB.NET) that runs 24/7. It queries a Web service 5 to 10 times per hour. About 2 or 3 times a month, it fails. The log indicates that it sends the request to the Web...
0
by: Glen Wolinsky | last post by:
I am creating a Windows service that will check a request queue (database) for pending requests. It will then process each individual request until completed, wait a set time interval and then...
5
by: chris.hearson | last post by:
How do I programmatically prevent a service from stopping? I want to be able to keep my service running (started), under certain conditions, when a user tries to stop it. I have tried throwing an...
6
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class...
10
by: archana | last post by:
Hi all, I am having one windows service which is updating to database. On 'Onstop i want to wait till current updation complete. How will i do this? Because if i write some lengthy code on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.