Using py2exe to wrap a service?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maria.Reinhammar@accalon.com

    #1

    Using py2exe to wrap a service?

    I have an app using active_director y.py and the std module asyncore in
    a Windows Service.
    Works perfectly!
    That is, until I try to use py2exe to create a standalone (need to
    avoid installing the entire Python etc. on the target system).

    When I try to start the installed Service, the system tells me it
    terminates prematurely
    and in the event log I find:
    The instance's SvcRun() method failed
    File "win32serviceut il.pyc", line 785, in SvcRun
    File "XXProxySvc.pyc ", line 126, in SvcDoRun
    File "XXProxySvc.pyc ", line 94, in setup
    File "D:\projects\XX Proxy\DB.py", line 54, in loadFromAD
    File "active_directo ry.pyc", line 402, in search
    File "active_directo ry.pyc", line 398, in root
    File "active_directo ry.pyc", line 371, in AD
    File "active_directo ry.pyc", line 378, in _root
    File "win32com\clien t\__init__.pyc" , line 73, in GetObject
    File "win32com\clien t\__init__.pyc" , line 88, in Moniker
    pywintypes.com_ error: (-2147221020, 'Invalid syntax', None, None)

    The offending line is:
    import active_director y as AD
    ....
    for item in AD.search ("objectCategor y='Person'"):
    ....

    I.e. the call to AD.search() is the entry point to the problem.

    The setup.py is (pretty straight forward..):
    from distutils.core import setup
    import py2exe

    class Target:
    def __init__(self, **kw):
    self.__dict__.u pdate(kw)
    # for the versioninfo resources
    self.version = "0.9.0"
    self.company_na me = "My Company"
    self.copyright = "My Company (c)"
    self.name = "FilterProx y"

    ############### ############### ############### ############### ####
    # a NT service, modules is required
    myservice = Target(
    # used for the versioninfo resource
    description = "AD Driven Mail Filter",
    # what to build. For a service, the module name (not the
    # filename) must be specified!
    modules = ["ProxySvc"]
    )

    excludes = []
    setup(options = {"py2exe": {# create a compressed zip archive
    #"compressed ": 1,
    #"optimize": 2,
    "excludes": excludes
    }
    },
    service=[myservice]
    )

    'elp! Pleeeez!

  • Larry Bates

    #2
    Re: Using py2exe to wrap a service?

    Maria.Reinhamma r@accalon.com wrote:
    I have an app using active_director y.py and the std module asyncore in
    a Windows Service.
    Works perfectly!
    That is, until I try to use py2exe to create a standalone (need to
    avoid installing the entire Python etc. on the target system).
    >
    When I try to start the installed Service, the system tells me it
    terminates prematurely
    and in the event log I find:
    The instance's SvcRun() method failed
    File "win32serviceut il.pyc", line 785, in SvcRun
    File "XXProxySvc.pyc ", line 126, in SvcDoRun
    File "XXProxySvc.pyc ", line 94, in setup
    File "D:\projects\XX Proxy\DB.py", line 54, in loadFromAD
    File "active_directo ry.pyc", line 402, in search
    File "active_directo ry.pyc", line 398, in root
    File "active_directo ry.pyc", line 371, in AD
    File "active_directo ry.pyc", line 378, in _root
    File "win32com\clien t\__init__.pyc" , line 73, in GetObject
    File "win32com\clien t\__init__.pyc" , line 88, in Moniker
    pywintypes.com_ error: (-2147221020, 'Invalid syntax', None, None)
    >
    The offending line is:
    import active_director y as AD
    ...
    for item in AD.search ("objectCategor y='Person'"):
    ...
    >
    I.e. the call to AD.search() is the entry point to the problem.
    >
    The setup.py is (pretty straight forward..):
    from distutils.core import setup
    import py2exe
    >
    class Target:
    def __init__(self, **kw):
    self.__dict__.u pdate(kw)
    # for the versioninfo resources
    self.version = "0.9.0"
    self.company_na me = "My Company"
    self.copyright = "My Company (c)"
    self.name = "FilterProx y"
    >
    ############### ############### ############### ############### ####
    # a NT service, modules is required
    myservice = Target(
    # used for the versioninfo resource
    description = "AD Driven Mail Filter",
    # what to build. For a service, the module name (not the
    # filename) must be specified!
    modules = ["ProxySvc"]
    )
    >
    excludes = []
    setup(options = {"py2exe": {# create a compressed zip archive
    #"compressed ": 1,
    #"optimize": 2,
    "excludes": excludes
    }
    },
    service=[myservice]
    )
    >
    'elp! Pleeeez!
    >
    You may want to post this on gmane.comp.pyth on.py2exe also.

    I'm going to try to guess what the problem is, but it is a little hard to tell
    from here. py2exe does its best to find all the modules required to create the
    ..exe. Sometimes modules do dynamic imports, etc. of modules that "fool" py2exe.
    I'm guessing that this is the case and that you will need to manually include
    the missing module. Most such errors seem to fall into this category. Hope
    this at least points you in the correct direction.

    -Larry Bates

    Comment

    • MaR

      #3
      Re: Using py2exe to wrap a service?

      Thanks guys! :o)

      It seems that no module is missing since the Service starts and the
      error message seem to indicate an error in the COM call to the AD.
      I would expect some other exception..

      I do have a separate thread for the asyncore.loop() as I otherwise
      would risk a lockup.

      I do not call pythoncom.CoIni tialize () as I tend to expect a module
      wrapping COM stuff to do that. Since I am not really into Windows, I
      have to ask you, do I make a wrong assumption here?

      Some further info that may be of interest:
      python 2.4.3
      active_director y 0.4
      py2exe 0.6.5
      pywin32 208
      The Service code is taken from MyService.py supplied with py2exe as a
      sample.

      Rgrds//M

      Comment

      Working...