[Twisted-Python] adbapi,adodbapi and pythoncom.CoInitialize()
I would like to use adbapi with the com based adodbapi. I found that the connect call hangs unless I add a call to pythoncom.CoInitialize(). I guess I'm now the tester for using adbapi and adodbapi on windows. I found a reference to the problem at: http://devnulled.com/archives/python.php For a crude test I added pythoncom.CoInitialize() when a new connection is made in twisted.enterprise.adbapi.ConnectionPool.connect() The connection and sql query then run successfully. # import pythoncom import sys sys.coinit_flags = 0 pythoncom.CoInitialize() [ COM code here... ] pythoncom.CoUninitialize()
On Mon, Jun 14, 2004 at 05:47:45PM -0600, Craig H. Anderson wrote:
I would like to use adbapi with the com based adodbapi. I found that the connect call hangs unless I add a call to pythoncom.CoInitialize().
That doesn't surprise me, seeing as adbapi runs stuff in threads to make it asynchronous, and COM requires each thread that uses COM stuff to be CoInitialize()d. I'm not sure how to cleanly arrange for that to happen, though. Perhaps something like: ---- import pythoncom from twisted.python import threadpool from twisted.enterprise import adbapi class COMThreadPool(threadpool.ThreadPool): def _worker(self, o): pythoncom.CoInitialize() threadpool.ThreadPool._worker(o) pythoncom.CoUninitialize() class COMConnectionPool(adbapi.ConnectionPool): def __init__(self, dbapiName, *args, **kwargs): adbapi.ConnectionPool.__init__(self, dbapiName, *args, **kwargs) self.threadpool = COMThreadPool(self.min, self.max) ---- Then use COMConnectionPool rather than adbapi.ConnectionPool. -Andrew.
participants (2)
-
Andrew Bennetts
-
Craig H. Anderson