Skip to content

Commit 9cd29eb

Browse files
committed
move sys.coinit_flags check to load_library.py
1 parent b2f4452 commit 9cd29eb

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

msl/loadlib/__init__.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
"""
22
Load a shared library.
33
"""
4-
import sys
5-
6-
from . import utils
7-
from ._version import __version__
8-
from ._version import __version_info__
4+
from .__about__ import __author__
5+
from .__about__ import __copyright__
6+
from .__about__ import __version__
7+
from .__about__ import version_info
98
from .client64 import Client64
109
from .constants import IS_PYTHON_64BIT
1110
from .exceptions import ConnectionTimeoutError
1211
from .exceptions import ResponseTimeoutError
1312
from .exceptions import Server32Error
1413
from .load_library import LoadLibrary
1514
from .server32 import Server32
16-
17-
__author__: str = 'Measurement Standards Laboratory of New Zealand'
18-
__copyright__: str = f'\xa9 2017 - 2024, {__author__}'
19-
20-
version_info = __version_info__
21-
"""Contains the version information as a (major, minor, micro, releaselevel) named tuple."""
22-
23-
if not hasattr(sys, 'coinit_flags'):
24-
# Configure comtypes to use COINIT_MULTITHREADED when it is imported.
25-
# This avoids the following exception from being raised:
26-
# [WinError -2147417850] Cannot change thread mode after it is set
27-
sys.coinit_flags = 0x0
15+
from .utils import generate_com_wrapper
16+
from .utils import get_com_info

msl/loadlib/load_library.py

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
PathLike = TypeVar('PathLike', str, bytes, os.PathLike)
3333
"""A :term:`path-like object`."""
3434

35+
if IS_WINDOWS and not hasattr(sys, 'coinit_flags'):
36+
# https://pywinauto.readthedocs.io/en/latest/HowTo.html#com-threading-model
37+
# Configure comtypes for Multi-Threaded Apartment model (MTA)
38+
# This avoids the following exception from being raised:
39+
# [WinError -2147417850] Cannot change thread mode after it is set
40+
sys.coinit_flags = 0
41+
3542

3643
class LoadLibrary:
3744

0 commit comments

Comments
 (0)