[Zope] Help -> Problem with NT Service,External Method,COM
S S
thewholeenchillada@hotmail.com
Thu, 28 Mar 2002 21:38:25 -0600
Hi there,
I have this strange problem cropping up in Zope. I have no idea why its
happening even after hours of trying to figure it out.
Heres the problem :
I have developed a Python code to open Microsoft Word through the win32com
package and produce a document depending on the user's parameters and some
predecided formatting.
Here's a snippet followd by my problem description :
import sys
sys.coinit_flags=0
COINIT_FREETHREADED=0
import os
import string
import pythoncom
import win32com
from win32com.client import Dispatch
def
run_pyth_worddoc_gen_module(rootdir,reqtitle,reqno,date,responsibleperson,signature,datasubmitted,vermessage,components=None):
pythoncom.CoInitializeEx(COINIT_FREETHREADED)
myword=None
try:
logfile=open(rootdir + '\\verification_generator.log','a')
logfile.write('\nstarting..')
myword=None
myword = win32com.client.Dispatch('Word.Application')
logfile.write('\nstarting..0')
myword.Visible = 0
logfile.write('\nstarting..1')
mydoc = myword.Documents.Add(Template=rootdir +
'\\python_verification_project1.dot')
logfile.write('\nopened word')
selection = myword.Selection
i=selection.MoveRight(Unit=1,Count=12)
i=selection.TypeText(Text=reqtitle)
i=selection.MoveDown(Unit=5, Count=2)
I wrote the code for it and ran it from Python and had no problems
generating the Word document.
The logfile which i use also shows no problems. Now,I tried calling this
method from Zope,by importing it as an External Method. And I couldnt go
beyond this line :
myword = win32com.client.Dispatch('Word.Application')
My logfile shows only "starting..", ie. the line before the above code is
called. I have Zope running as an NT Service.I also have another version of
Python installed(2.1) apart from the Python which comes with Zope. It gets
weirder. After stopping the NT Service and running it from the startup.bat
file(throws up the COmmand prompt window) and running the External Method
from ZOpe,the code works like a dream.
There seems to be some problem when I run Zope as a service,it stops at
the Dispatch command. On viewing the Windows Task Manager,WINWORD(exe for
Word) throws up when the code is called,but when the code works(when Im
running it straight from Python or running it from Zope started from the
start.bat file),the WINWORD process seems to take memory(13megs) and when
finished it exits cleanly.
However when running from the Zope started by the NT Service, as mentioned
it hangs at the Dispatch line,but the Task Manager shows that WINWORD
process has started but its memory usage is static at 2.884 MB.
The error stacktrace is as follows when Zope runs as an NT Service:
Traceback (innermost last):
File E:\PROGRA~1\WebSite\lib\python\ZPublisher\Publish.py, line 150, in
publish_module
File E:\PROGRA~1\WebSite\lib\python\ZPublisher\Publish.py, line 114, in
publish
File E:\PROGRA~1\WebSite\lib\python\Zope\__init__.py, line 158, in
zpublisher_exception_hook
(Object: verification)
File E:\PROGRA~1\WebSite\lib\python\ZPublisher\Publish.py, line 98, in
publish
File E:\PROGRA~1\WebSite\lib\python\ZPublisher\mapply.py, line 88, in
mapply
(Object: run_pyth_worddoc_gen_module)
File E:\PROGRA~1\WebSite\lib\python\ZPublisher\Publish.py, line 39, in
call_object
(Object: run_pyth_worddoc_gen_module)
File
E:\PROGRA~1\WebSite\lib\python\Products\ExternalMethod\ExternalMethod.py,
line 202, in __call__
(Object: run_pyth_worddoc_gen_module)
File E:\Program Files\WebSite\Extensions\run_pyth_worddoc_gen_module.py,
line 24, in run_pyth_worddoc_gen_module
File e:\program files\Python21\win32com\client\__init__.py, line 92, in
Dispatch
File e:\program files\Python21\win32com\client\dynamic.py, line 81, in
_GetGoodDispatchAndUserName
File e:\program files\Python21\win32com\client\dynamic.py, line 72, in
_GetGoodDispatch
com_error: (see above)
Any ideas people?.
Thanks and Regards,
Shravan
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com