thread and win32com.client problem

R

Ray

Hi, I have a problem with thread and win32com.client
running python 2.5 on vista (activestate python)

import win32com.client, thread
def child(test):
problem=win32com.client.Dispatch("WScript.Shell")
print 'hello from thread', test
def parent():
i=0
while 1:
i+=1
thread.start_new(child,('abc',))
if raw_input()=='q': break
parent()

above codes will give me error when I run it.
but if without the line
problem=win32com.client.Dispatch("WScript.Shell")
it just works fine.


errors are:

Unhandled exception in thread started by <function child at
0x01E690F0>
Traceback (most recent call last):
File "C:\Users\Test\Desktop\Test\test_thread.py", line 3, in child
problem=win32com.client.Dispatch("WScript.Shell")
File "C:\Python25\lib\site-packages\win32com\client\__init__.py",
line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName
(dispatch,userName,clsctx)
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py",
line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py",
line 78, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221008, 'CoInitialize has not been
called.', None, None)
Traceback (most recent call last):
File "C:\Users\Test\Desktop\Test\test_thread.py", line 11, in
<module>
parent()
File "C:\Users\Test\Desktop\Test\test_thread.py", line 10, in parent
if raw_input()=='q': break


Thanks for any help.
 

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
474,056
Messages
2,570,446
Members
47,097
Latest member
MarionMajo

Latest Threads

Top