microsoft / xlang

MIT License
877 stars 103 forks source link

"Cannot change thread mode after it is set" RunTime error in Python #761

Closed VellichorPrism closed 3 years ago

VellichorPrism commented 3 years ago

I created a project that displays a Windows toast notification. When I run my code in PyCharm, the script executes normally until completion. After compiling using PyInstaller and running the generated exe, I get an error for one of the 'winrt' imports:

Traceback (most recent call last):
  File "notification.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "message.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "winrt\__init__.py", line 4, in <module>
RuntimeError: Cannot change thread mode after it is set.
[9720] Failed to execute script 'notification' due to unhandled exception!

My imports for 'winrt' are:

import winrt.windows.ui.notifications as notifications
import winrt.windows.data.xml.dom as dom

If anyone one knows why I get this error, I would appreciate any help!

dlech commented 3 years ago

See #690.