[Python-ideas] Threading hooks and disable gc per thread

Jim Jewett jimjjewett at gmail.com
Fri May 27 16:01:32 CEST 2011


On Fri, May 27, 2011 at 6:04 AM, Thomas Heller <theller at ctypes.org> wrote:
> Here is my idea to fix this from within Python:
> The COM objects, when created, keep the name of the currently executing
> thread. In the __del__ method, where the cleanup of the COM object
> happens by calling the COM .Release() method, a check is made if the
> current thread is the allowed one or not.  If it is the wrong thread,
> the COM object is kept alive by appending it to some list. The list is
> stored in a global dictionary indexed by the thread name.

Of course, this means that multiple COM objects in the same cycle
become uncollectable, which again argues for the __close__ idiom.
(Just like __del__ except that it can be run more than once, and it if
there are multiples in a cycle, they are run in arbitrary order
instead of deferred.)  Alternatively, you might get away with some
wonky proxy objects as part of the COM wrapping.

-jJ



More information about the Python-ideas mailing list