473,387 Members | 1,550 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,387 software developers and data experts.

win32 service and time.sleep()

rbt
I have a win32 service written in Python. It works well. It sends a
report of the status of the machine via email periodically. The one
problem I have is this... while trying to send an email, the script
loops until a send happens and then it breaks. Should it be unable to
send, it sleeps for 10 minutes with time.sleep(600) and then wakes and
tries again. This is when the problem occurs. I can't stop the service
while the program is sleeping. When I try, it just hangs until a reboot.
Can some suggest how to fix this?

Thanks,
rbt
Sep 20 '05 #1
2 4017
On Tue, 20 Sep 2005 10:49:13 -0400, rbt wrote:
I have a win32 service written in Python. It works well. It sends a
report of the status of the machine via email periodically. The one
problem I have is this... while trying to send an email, the script
loops until a send happens and then it breaks. Should it be unable to
send, it sleeps for 10 minutes with time.sleep(600) and then wakes and
tries again. This is when the problem occurs. I can't stop the service
while the program is sleeping. When I try, it just hangs until a reboot.
Can some suggest how to fix this?


You could try doing it the hard way. In a loop, sleep for 1-5 seconds at
a time. Everytime you complete a sleep, check the elapsed time. If the
elapsed time is >= the total sleep duration, fall out of the sleep loop
and try your email again. This should allow your service to stop within
1-5 seconds of your request while imposing little to no load on the system.

Sep 20 '05 #2
Oracle wrote:
On Tue, 20 Sep 2005 10:49:13 -0400, rbt wrote:
I have a win32 service written in Python. It works well. It sends a
report of the status of the machine via email periodically. The one
problem I have is this... while trying to send an email, the script
loops until a send happens and then it breaks. Should it be unable to
send, it sleeps for 10 minutes with time.sleep(600) and then wakes and
tries again. This is when the problem occurs. I can't stop the service
while the program is sleeping. When I try, it just hangs until a reboot.
Can some suggest how to fix this?


You could try doing it the hard way. In a loop, sleep for 1-5 seconds at
a time. Everytime you complete a sleep, check the elapsed time. If the
elapsed time is >= the total sleep duration, fall out of the sleep loop
and try your email again. This should allow your service to stop within
1-5 seconds of your request while imposing little to no load on the system.


I adopted that solution just last week. When you wake (every few
seconds), you check for a stop flag (and exit if needed of
course) before checking if its time to do work-work. Works a treat.

Another option is to use a threading.Condition, and have the
service thread wait(600). The thread that calls to stop the
service can set the stop flag and then notify() the Condition.

Steve
Sep 22 '05 #3

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

Similar topics

0
by: Tom Brown | last post by:
Hi, I created a win32 service for XPPro called N4010ATestService.py (see below). The service runs as a particular user with administrative rights. It starts a thread that creates a simple socket...
3
by: rbt | last post by:
How can I safely append a crontab entry to a crontab file progammatically with Python? I need to handle crontabs that currently have entries and crontabs that are empty. Also, I'd like this to...
2
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
3
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...
3
by: tshad | last post by:
I created a service in VS 2003 and the code works fine as an application, but not as a service. It installs fine, but when I try to start it, it tells me it was unable to start. Am I missing...
4
by: drodrig | last post by:
Hi. I am trying to close/kill all processes that show visible windows on Windows XP. So far I've created a script that uses win32gui.EnumWindows to iterate through all windows, check for which...
4
by: kkt49 | last post by:
# vim: et sw=4 ts=8 sts from wxPython.wx import * import sys, os, time import pywintypes import win32serviceutil import win32service import win32event import win32process
0
by: Tim Golden | last post by:
Lowell Alleman wrote: Well you've certainly picked a ticklish area to run into problems with ;). First, forget about the threading aspects for the moment. AFAICT the smallest program which...
10
by: tshad | last post by:
I have a Windows Service that I need to put to sleep for about 10-20 minutes. The problem is that if you try to shut it down during this time, it will tell you that the service didn't respond in...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.