Someone contacted me the other day to say that he was trying to use my active_directory module to backend a Trac authentication plugin. His code worked fine in a test harness, but running against the standalone tracd server, it crashed Python.
Now, as I pointed out to him, it takes usually two things to crash Python: an extension module; and threading. We definitely had the first (the win32com module) but not evidently the second. After some toing-and-froing, it became clear that tracd did indeed use a threading mixin and that, if this was removed, the problem went away.
As it stands now (I’m waiting to hear back from the OP) the problem is almost certainly down to the face that the module-level convenience functions work against a module global, which is not therefore thread-safe. That, the programmer can — and should — work around by instantiating his own AD object within the thread. The second thing, though, which I need to rectify in the module itself is that it uses a global ADO connection. This must have seemed like a good idea at the time, but in retrospect is bound to give problems of this sort.
In addition, of course, the programmer will need to do the CoInitialize / CoUninitialize dance to let COM know that we’re threading and that it needs to do its stuff.