Using py2exe to wrap a service?

M

Maria.Reinhammar

I have an app using active_directory.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 "win32serviceutil.pyc", line 785, in SvcRun
File "XXProxySvc.pyc", line 126, in SvcDoRun
File "XXProxySvc.pyc", line 94, in setup
File "D:\projects\XXProxy\DB.py", line 54, in loadFromAD
File "active_directory.pyc", line 402, in search
File "active_directory.pyc", line 398, in root
File "active_directory.pyc", line 371, in AD
File "active_directory.pyc", line 378, in _root
File "win32com\client\__init__.pyc", line 73, in GetObject
File "win32com\client\__init__.pyc", line 88, in Moniker
pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None)

The offending line is:
import active_directory as AD
....
for item in AD.search ("objectCategory='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__.update(kw)
# for the versioninfo resources
self.version = "0.9.0"
self.company_name = "My Company"
self.copyright = "My Company (c)"
self.name = "FilterProxy"

################################################################
# 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!
 
L

Larry Bates

I have an app using active_directory.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 "win32serviceutil.pyc", line 785, in SvcRun
File "XXProxySvc.pyc", line 126, in SvcDoRun
File "XXProxySvc.pyc", line 94, in setup
File "D:\projects\XXProxy\DB.py", line 54, in loadFromAD
File "active_directory.pyc", line 402, in search
File "active_directory.pyc", line 398, in root
File "active_directory.pyc", line 371, in AD
File "active_directory.pyc", line 378, in _root
File "win32com\client\__init__.pyc", line 73, in GetObject
File "win32com\client\__init__.pyc", line 88, in Moniker
pywintypes.com_error: (-2147221020, 'Invalid syntax', None, None)

The offending line is:
import active_directory as AD
...
for item in AD.search ("objectCategory='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__.update(kw)
# for the versioninfo resources
self.version = "0.9.0"
self.company_name = "My Company"
self.copyright = "My Company (c)"
self.name = "FilterProxy"

################################################################
# 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.python.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
 
M

MaR

Thanks guys! :eek:)

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.CoInitialize () 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_directory 0.4
py2exe 0.6.5
pywin32 208
The Service code is taken from MyService.py supplied with py2exe as a
sample.

Rgrds//M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top