How to use python and windows com in pyramid (threads)?

て烟熏妆下的殇ゞ 提交于 2019-12-24 10:37:58

问题


I'm connecting to MS Word by win32com.client.Distpatch function and on the second request i've got error: 'CoInitialize has not been called.' I've found this topic:

http://www.velocityreviews.com/forums/t328097-coinitialize-error-when-using-adodbapi.html

and got that I have to call of CoInitialize in new thread. So question is where to call CoInitialize function in pyramid.


回答1:


So i added call of CoInitialize in function:

@subscriber(NewRequest)
def new_request_subscriber(event):
    import pythoncom
    pythoncom.CoInitialize()

and works without exception.



来源:https://stackoverflow.com/questions/12230240/how-to-use-python-and-windows-com-in-pyramid-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!