Discussion:
[Py2exe-users] win32com.client.Dispatch. Having problems again.
Gordon Scott
2006-04-11 23:30:54 UTC
Permalink
Hi all,

Cany anyone think of a reason why calling win32com.client.Dispatch() would
simply hang when running under py2exe?
I've got a 3rd party object I'm trying to use and my script runs fine when
run from the console. When I build a service exe it simply hangs when
creating the COM object.
I thought there might be a problem with making sure I imported the correct
items, so I switched my code to instantiate the ImageMagick COM object that
I used in a prior project, but that created the COM object just fine when
compiled as a service...

Could this be a problem with threading styles between the exe and the COM
object?

my script is doing something like this

import pythoncom
import win32com.client
import win32com.gen_py
import win32com.gen_py.SMSC
from win32com.client import gencache, constants, Dispatch

pythoncom.CoInitialize()

#tthis works fine...
magick = Dispatch("ImageMagickObject.MagickImage.1")
del(magick)

#exe hangs on this call whereas script runs fine...
myobj = Dispatch("SMSCConnectivitySDK.SMPP.1")
.
.

del(myobj)
pythoncom.CoUninitialize()
Gordon Scott
2006-04-12 00:18:47 UTC
Permalink
I installed the service and ran from the .py file directlly. Works like a
champ in this regard.
So it definitely appears that something is being run differently when run
from the py2exe service...
Some COM objects are not suitable for use in a service environment and
there
isn't much Python can do to work around it. Having the service
flagged to
"interact with the desktop", or setting an explicit username for the
service
to use may help though...
The COM object definitely works in a service environment. We are
currentlly using the com object in a C++ based NT Service.
I'm trying to build a service to do some additional tasks to complement
the main service, I was hoping to be able to do this in Python however as it
is so much easier that way.
Gordon Scott
2006-04-12 00:37:37 UTC
Permalink
Hey Mark,

Good news. I ran across this thread that you made a post to last year.
http://www.thescripts.com/forum/thread26897.html

So I added the following right before importing pythoncom

# 0 == pythoncom.COINIT_MULTITHREADED # !!!!!
sys.coinit_flags = 0
import pythoncom

lo and behold the py2exe service now works!

Since I'm still a relative noob as far as COM is concerned, can you explain
what that line of code did? I'm assuming that the exe generated by py2exe
must have been running a different COM threading model than standard
python? Just trying to figure all this out...

Gordo
Jeff Peery
2006-04-12 03:25:42 UTC
Permalink
hello, I have a py2exe script that I have attached. I am using wxpython, matplotlib, and numpy. the setup script runs ok, but when I run my application I get this error message:

"ImportError: No module named wx"

this occurs exactly on the line where I import the wx module (i.e., 'import wx')

how might I modify my script so that my application recognizes the wx module? thanks!

Jeff


---------------------------------
New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.
Jimmy Retzlaff
2006-04-14 17:43:25 UTC
Permalink
Jeff Peery wrote:
...
Post by Jeff Peery
"ImportError: No module named wx"
this occurs exactly on the line where I import the wx module (i.e.,
'import wx')

I use wxPython all the time and it doesn't normally take anything
special. I don't notice any problems in your setup.py (although it is
large, so I may have missed something). Is your application doing
anything like explicitly setting the version of wx to use? I'm referring
to this... http://wiki.wxpython.org/index.cgi/MultiVersionInstalls. I
don't use that functionality (I just import the default version), so I
don't know how it interacts with py2exe.

Is it failing when you run the version in the dist directory, the
version installed by the generated Inno installer, or both?

Jimmy
Jeff Peery
2006-04-14 21:15:07 UTC
Permalink
the problem started when I switched to using numpy instead of numeric. I can run the inno setup, it installs, but when I launch it it bombs out.

I have no idea why this is happening. any clues? thanks.

Jeff

Jimmy Retzlaff <***@retzlaff.com> wrote:
Jeff Peery wrote:
...
Post by Jeff Peery
"ImportError: No module named wx"
this occurs exactly on the line where I import the wx module (i.e.,
'import wx')

I use wxPython all the time and it doesn't normally take anything
special. I don't notice any problems in your setup.py (although it is
large, so I may have missed something). Is your application doing
anything like explicitly setting the version of wx to use? I'm referring
to this... http://wiki.wxpython.org/index.cgi/MultiVersionInstalls. I
don't use that functionality (I just import the default version), so I
don't know how it interacts with py2exe.

Is it failing when you run the version in the dist directory, the
version installed by the generated Inno installer, or both?

Jimmy


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Py2exe-users mailing list
Py2exe-***@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/py2exe-users



---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2ยข/min or less.
Loading...