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

Python service gets interrupted function call

Hi All,
I wanted to know how to handle events like 'logoff' in the main thread
so that any process which is being run by svcDoRun method of service
does not get 'interrupted function call' exception.

I am posting a very simple service program , and i want to know that
is there a way to handle such interrupts without explicitly calling
try except block over blocking calls.

Here is the example which is getting interrupted exception at logoff.
================================================== =====
import os, time, sys
import win32serviceutil, win32service
import pywintypes, win32con, winerror
# Use "import *" to keep this looking as much as a "normal" service
# as possible. Real code shouldn't do this.
from win32event import *
from win32file import *
from win32pipe import *
from win32api import *
from ntsecuritycon import *

import servicemanager

import traceback
import thread, time

class TrialService(win32serviceutil.ServiceFramework):
_svc_name_ = "TrialService"
_svc_display_name_ = "TrialService"
_svc_description_ = "TrialService"
_exe_name_ = "C:/Python24/Lib/site-packages/win32/
pythonservice.exe"

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = CreateEvent(None, 0, 0, None)
self.overlapped = pywintypes.OVERLAPPED()
self.overlapped.hEvent = CreateEvent(None,0,0,None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP _PENDING)
SetEvent(self.hWaitStop)

def SvcDoRun(self):
time.sleep(1000)

def ctrl_handler(ctrl_type):
return True

if __name__ =='__main__':
SetConsoleCtrlHandler(ctrl_handler, True)
win32serviceutil.HandleCommandLine(TrialService)

================================================== ======

In actual call i just want to call my app in place of time.sleep but
my app will have blocking code segments.
Any help will be greatly appreciated .
Thanks
Ashish

Oct 10 '07 #1
1 2155

"ashish" <as********@gmail.comwrote in message news:11**********************@50g2000hsm.googlegro ups.com...
Hi All,
I wanted to know how to handle events like 'logoff' in the main thread
so that any process which is being run by svcDoRun method of service
does not get 'interrupted function call' exception.

I am posting a very simple service program , and i want to know that
is there a way to handle such interrupts without explicitly calling
try except block over blocking calls.

Here is the example which is getting interrupted exception at logoff.
================================================== =====
import os, time, sys
import win32serviceutil, win32service
import pywintypes, win32con, winerror
# Use "import *" to keep this looking as much as a "normal" service
# as possible. Real code shouldn't do this.
from win32event import *
from win32file import *
from win32pipe import *
from win32api import *
from ntsecuritycon import *

import servicemanager

import traceback
import thread, time

class TrialService(win32serviceutil.ServiceFramework):
_svc_name_ = "TrialService"
_svc_display_name_ = "TrialService"
_svc_description_ = "TrialService"
_exe_name_ = "C:/Python24/Lib/site-packages/win32/
pythonservice.exe"

def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = CreateEvent(None, 0, 0, None)
self.overlapped = pywintypes.OVERLAPPED()
self.overlapped.hEvent = CreateEvent(None,0,0,None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP _PENDING)
SetEvent(self.hWaitStop)

def SvcDoRun(self):
time.sleep(1000)

def ctrl_handler(ctrl_type):
return True

if __name__ =='__main__':
SetConsoleCtrlHandler(ctrl_handler, True)
win32serviceutil.HandleCommandLine(TrialService)

================================================== ======

In actual call i just want to call my app in place of time.sleep but
my app will have blocking code segments.
Any help will be greatly appreciated .
Thanks
Ashish
Use win32api.Sleep, and pass True for the second arg.

Roger

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Oct 12 '07 #2

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

Similar topics

0
by: Nazgul | last post by:
Hi! Sorry if I posted it twice... I need your help... I have the following problem. I've implemented the python Windows Service which behaves like a log supervisor. If the space used by log...
11
by: Nicolas Lehuen | last post by:
Hi, I hope this is not a FAQ, but I have trouble understanding the behaviour of the super() built-in function. I've read the excellent book 'Python in a Nutshell' which explains this built-in...
3
by: fdsl ysnh | last post by:
--- python-list-request@python.orgдµÀ: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, > visit >...
5
by: BobAchgill | last post by:
I have a Form that on a timer uses FTP to update data on the local disk. I would like this Form to start on boot of the computer and stay running still shutdown. Like putting it in the...
4
by: ggillard | last post by:
Hi, I'm new to writing services and found it pretty easy using VB.NET. My service has an internal timer that fires every 3 seconds. Each time it fires it opens a SQL DB and looks for a...
0
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...
5
by: momobear | last post by:
I feel really puzzled about fellowing code, please help me finger out what problem here. import threading class workingthread(threading.Thread): def __init__(self): self.quitEvent =...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.