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

win32 Service: path to .py script

Hi,

I have a testservice.py (see below). I installed the Windows-Service
successfully. (via commandlineoption install)
The problem is that it runs only when it is in c:\windows\system32 or in
the python path.
I added the desired path (Y:\) to the PYTHONPATH environment variable
for the system account and rebooted.
When I start command line python and do a import testservice everything
is fine.
Starting the service with the script only in Y:\ gives the error in the
event log:

Python could not import the service's module

exceptions.ImportError: No module named testservice

Thanks for your help.

--
Greg

testservice.py:

import win32serviceutil, win32service
import servicemanager
import win32api
import win32event
import sys

class TestPipeService(win32serviceutil.ServiceFramework) :
_svc_name_ = "MDE Dispatcher"
_svc_display_name_ = "MDE-Dispatcher"
_svc_description_ = "Dispatches machine events from the Siemens ODC
to registrered MDE clients (windows) over the network via XML-RPC"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP _PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
# Write an event log record - in debug mode we will also
# see this message printed.
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, '')
)

while 1:
win32api.Sleep(2)
rc = win32event.WaitForSingleObject(self.hWaitStop, 2000)
if rc == win32event.WAIT_OBJECT_0:
break
# Write another event log record.
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STOPPED,
(self._svc_name_, " TEST ")
)
if __name__=='__main__':
win32serviceutil.HandleCommandLine(TestPipeService )

Sep 19 '06 #1
2 4386
Gregor Horvath wrote:
Hi,

I have a testservice.py (see below). I installed the Windows-Service
successfully. (via commandlineoption install)
The problem is that it runs only when it is in c:\windows\system32 or in
the python path.
I added the desired path (Y:\) to the PYTHONPATH environment variable
for the system account and rebooted.
When I start command line python and do a import testservice everything
is fine.
Starting the service with the script only in Y:\ gives the error in the
event log:

Python could not import the service's module

exceptions.ImportError: No module named testservice

Thanks for your help.

--
Greg

testservice.py:

import win32serviceutil, win32service
import servicemanager
import win32api
import win32event
import sys

class TestPipeService(win32serviceutil.ServiceFramework) :
_svc_name_ = "MDE Dispatcher"
_svc_display_name_ = "MDE-Dispatcher"
_svc_description_ = "Dispatches machine events from the Siemens ODC
to registrered MDE clients (windows) over the network via XML-RPC"
def __init__(self, args):
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)

def SvcStop(self):
self.ReportServiceStatus(win32service.SERVICE_STOP _PENDING)
win32event.SetEvent(self.hWaitStop)
def SvcDoRun(self):
# Write an event log record - in debug mode we will also
# see this message printed.
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STARTED,
(self._svc_name_, '')
)

while 1:
win32api.Sleep(2)
rc = win32event.WaitForSingleObject(self.hWaitStop, 2000)
if rc == win32event.WAIT_OBJECT_0:
break
# Write another event log record.
servicemanager.LogMsg(
servicemanager.EVENTLOG_INFORMATION_TYPE,
servicemanager.PYS_SERVICE_STOPPED,
(self._svc_name_, " TEST ")
)
if __name__=='__main__':
win32serviceutil.HandleCommandLine(TestPipeService )
I believe that your problem is that services run under Local
System account. Normally Local System account would not have
a drive mapping Y:\. You can change the account that a service
runs under in the Service Manager-Log On tab. Normally you
wouldn't run services from mapped drives, they would be
installed on local machine and started from there. If services
need to access mapped drives, you need to put full UNC
pathnames to access them or run the services under an account
that has the drives mapped properly.

-Larry Bates
Sep 19 '06 #2
Larry Bates schrieb:
I believe that your problem is that services run under Local
System account. Normally Local System account would not have
a drive mapping Y:\. You can change the account that a service
You are absolutly correct.
I moved the script to a local drive instead of a mapped network drive,
now it works perfectly.

Thank you a lot.

--
Servus, Gregor
Sep 19 '06 #3

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

Similar topics

2
by: Jorgen Grahn | last post by:
I couldn't think of a good solution, and it's hard to Google for... I write python command-line programs under Win2k, and I use the bash shell from Cygwin. I cannot use Cygwin's python package...
6
by: Laszlo Zsolt Nagy | last post by:
Sorry, I realized that the import zlib was not executed from my (working) service. So here is the question: why can't I use zlib from a win32 service? Is there any way to make it working? ...
1
by: knutsample | last post by:
Hello! I'm trying to associate a file extension to my wxPython script so that all I have to do is double click on the file and my python script will load up with the path of that file. For...
2
by: rbt | last post by:
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...
2
by: raghavendra | last post by:
Hi, How to run automatically windows service by using setup deployment insatllation script using visual studio 2003.? What i did is :-- 1. created a windows service & tested the same. 2....
4
by: Gav | last post by:
Hi all, I have written a program which seriously depends on an environment variable. When I set the env var for the system it caused me major problems unrelated to what I was trying to achieve....
3
by: Marshall | last post by:
Hello, I am wondering if it is possible to call a remote web service using ATLAS and if so, how. I have read several docs which show how to call a web service that is within the same project as...
2
by: Gregor Mosheh | last post by:
I'm trying to write a Win32 service. The following is straight from Python Programming on Win32 and it doesn't work. Is that book out of date; is there a new way to do services? I searched Google...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.