Differences between revisions 4 and 5
Revision 4 as of 2009-10-28 19:42:27
Size: 1354
Editor: ThomasHeller
Comment:
Revision 5 as of 2009-10-29 19:54:26
Size: 2562
Editor: Aahz
Comment: Add cmdline_style info
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

== Making services more like regular win32 apps ==

From http://osdir.com/ml/python.py2exe/2007-01/msg00003.html, update
your setup.py to look something like this:

{{{
myservice = Target(
    # used for the versioninfo resource
    description = "A sample Windows NT service",
    # what to build. For a service, the module name (not the
    # filename) must be specified!
    modules = ["MyService"],
    cmdline_style='pywin32',
    )

setup(
    service = [myservice],
    )
}}}

See `samples\advanced\setup.py` for more details.

Without the cmdline_style parameter, you get this output from running your
service in CMD:

{{{
Services are supposed to be run by the system after they have been installed.
These command line options are available for (de)installation:
        -help
        -install
        -remove
        -auto
        -disabled
        -interactive
        -user: <arg>
        -password: <arg>
Connecting to the Service Control Manager
Traceback (most recent call last):
  File "boot_service.py", line 173, in ?
pywintypes.error: (1063, 'StartServiceCtrlDispatcher', 'The service process could not connect to the service controller.')
}}}

Making services more like regular win32 apps

From http://osdir.com/ml/python.py2exe/2007-01/msg00003.html, update your setup.py to look something like this:

myservice = Target(
    # used for the versioninfo resource
    description = "A sample Windows NT service",
    # what to build. For a service, the module name (not the
    # filename) must be specified!
    modules = ["MyService"],
    cmdline_style='pywin32',
    )

setup(
    service = [myservice],
    )

See samples\advanced\setup.py for more details.

Without the cmdline_style parameter, you get this output from running your service in CMD:

Services are supposed to be run by the system after they have been installed.
These command line options are available for (de)installation:
        -help
        -install
        -remove
        -auto
        -disabled
        -interactive
        -user: <arg>
        -password: <arg>
Connecting to the Service Control Manager
Traceback (most recent call last):
  File "boot_service.py", line 173, in ?
pywintypes.error: (1063, 'StartServiceCtrlDispatcher', 'The service process could not connect to the service controller.')

Things that can go wrong with py2exe and services

within demos/advanced there is an example to create windows services with py2exe. It works quite out of the box.

Difficulties arise later on - as soon as you wanna do something REAL with that service.

Error Message

Python could not import the service's module 
  File "C:\ham\jds\syncservice.py", line 21, in ?
    import transinhalte
  File "C:\ham\jds\transinhalte.py", line 17, in ?
    import unite
  File "C:\ham\jds\unite.py", line 9, in ?
    import version 
exceptions.ImportError: dynamic module does not define init function (initversion)

yours might be different ... what went wrong????

Everything worked fine as long as I was running that service within debug mode. Then, starting it up as "real service", this error appeared.

a Mail of Gerald Haering showed me the light: when a service is started, all paths are TOTALLY DIFFERENT ANIMALS then in any other running state of python... so, the service tried to load version.dll, which is something that comes within windows/system32, and of course has NO Python init-code.

Solution

Make sure that NONE of your Python module names conflicts with ANY of the windows system dll names

py2exeAndWindowsServices (last edited 2015-12-07 09:41:17 by TijnGommans)