Skip to content

Commit bc8cf52

Browse files
author
cfarrow
committed
Moving imports outside of running code. This makes creation of event-related
objects more thread-safe. See http://docs.python.org/library/threading.html#importing-in-threaded-code. --HG-- extra : convert_revision : svn%3Aa2f44796-8cc0-49ac-b43f-6a96d556d52d/trunk%40584
1 parent 19cc3ff commit bc8cf52

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

comtypes/_comobject.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# COM object implementation
1313
from _ctypes import CopyComPointer
1414

15-
from comtypes import COMError, ReturnHRESULT, instancemethod
15+
from comtypes import COMError, ReturnHRESULT, instancemethod, _encode_idl
1616
from comtypes.errorinfo import ISupportErrorInfo, ReportException, ReportError
1717
from comtypes.typeinfo import IProvideClassInfo, IProvideClassInfo2
1818
from comtypes import IPersist
@@ -466,7 +466,6 @@ def __make_dispentry(self,
466466
# We build a _dispmap_ entry now that maps invkind and
467467
# dispid to implementations that the finder finds;
468468
# IDispatch_Invoke will later call it.
469-
from comtypes import _encode_idl
470469
paramflags = [((_encode_idl(x[0]), x[1]) + tuple(x[3:])) for x in argspec]
471470

472471
dispid = idlflags[0] # XXX can the dispid be at a different index? Check codegenerator.

comtypes/client/_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import comtypes.automation
66
import comtypes.typeinfo
77
import comtypes.connectionpoints
8+
from comtypes.client._generate import GetModule
89
import logging
910
logger = logging.getLogger(__name__)
1011

@@ -48,7 +49,6 @@ def FindOutgoingInterface(source):
4849
except KeyError:
4950
tinfo = pci.GetClassInfo()
5051
tlib, index = tinfo.GetContainingTypeLib()
51-
from comtypes.client import GetModule
5252
GetModule(tlib)
5353
interface = comtypes.com_interface_registry[str(guid)]
5454
logger.debug("%s using sinkinterface %s", source, interface)
@@ -243,7 +243,7 @@ def PumpEvents(timeout):
243243
# If the calling thread resides in a multithread apartment (MTA),
244244
# CoWaitForMultipleHandles calls the Win32 function
245245
# MsgWaitForMultipleObjects.
246-
246+
247247
hevt = ctypes.windll.kernel32.CreateEventA(None, True, False, None)
248248
handles = (ctypes.c_void_p * 1)(hevt)
249249
RPC_S_CALLPENDING = -2147417835

0 commit comments

Comments
 (0)