[Twisted-Python] adbapi,adodbapi and pythoncom.CoInitialize()

Andrew Bennetts andrew-twisted at puzzling.org
Mon Jun 14 20:11:15 EDT 2004

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

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):

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.


More information about the Twisted-Python mailing list