Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newly created gen_py modules sometimes fail to import in Python 3 #1595

Closed
SReicheltPTV opened this issue Oct 21, 2020 · 0 comments · Fixed by #1596
Closed

Newly created gen_py modules sometimes fail to import in Python 3 #1595

SReicheltPTV opened this issue Oct 21, 2020 · 0 comments · Fixed by #1596

Comments

@SReicheltPTV
Copy link
Contributor

When accessing a COM server using gen_py modules on demand, some modules randomly fail to import after they have been generated. This is highly machine-dependent; on most computers the problem does not manifest itself at all, but on some it is quite reproduceable, using e.g.

import sys, win32com.client
c = <some on-demand static dispatch COM object>
m = sys.modules[sys.modules[c.__module__].__package__]
for clsid in m.CLSIDToPackageMap:
    win32com.client.gencache.GetModuleForCLSID(clsid)

On some machines, this will throw a "module not found" exception after about 10 iterations.

The cause of the problem seems to be a breaking change in Python 3.3, which is documented at https://docs.python.org/3/library/importlib.html#importlib.import_module. Specifically, it is now necessary to call importlib.invalidate_caches before importing the newly generated module. I will attach a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant