Re: win32 Service: path to .py script



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
.



Relevant Pages

  • Re: Whats so funny? WAS Re: rotor replacement
    ... That I have to download and perhaps install them to use ... > * I have to download and build the MySQLdb package to talk to MySQL ... > servers from Python code ... I can write something using a core module instead of an external ...
    (comp.lang.python)
  • RE: Python 2.4 killing commercial Windows Python development ?
    ... > install fully useable Python on their Windows machines. ... > Quicksomething for Windows, or RealPlayer, ... The Windows application that I develop and distribute relies on Python ...
    (comp.lang.python)
  • Re: bytecode non-backcompatibility
    ... Unstable bytecodes makes updating to a newer version of Python very ... >>>tedious and risk breaking old scripts, ... > setup.py install" to install the library into site-package. ... each port has a list of all the other ports it depends ...
    (comp.lang.python)
  • HOWTO: Python 2.3 on Fedora Core 1 Linux
    ... About the 'new' Python ... Appendix A: Python Installation with Tkinter - edit: Modules/Setup.dist ... Be aware that it is always risky to install new software; ... # uncomment and/or edit those parts as indicated. ...
    (comp.lang.python)
  • Re: Python 2.4 killing commercial Windows Python development ?
    ... install fully useable Python on their Windows machines. ... different to me than having to install Shockwave, ... Quicksomething for Windows, or RealPlayer, ... The Windows application that I develop and distribute relies on Python ...
    (comp.lang.python)