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

Fix importing newly-created modules on Python 3 #172

Merged

Conversation

fxthomas
Copy link
Contributor

Python 3's import mechanism caches the contents of a directory
containing modules (such as comtypes.gen) and relies on the "modified
time" (mtime) attribute to determine if it needs to reload that
directory.

In Windows, the mtime is sometimes not updated very often when creating
modules in quick succession, which means that the mtime stays identical,
which then appears in comtype's case as random module import failures
when using a new COM object for the first time.

See https://stackoverflow.com/questions/52933869/why-does-importing-fails-after-creating-a-module-under-python-3-on-windows for a more detailed explanation.

(Fixes #161)

Python 3's import mechanism caches the contents of a directory
containing modules (such as comtypes.gen) and relies on the "modified
time" (mtime) attribute to determine if it needs to reload that
directory.

In Windows, the mtime is sometimes not updated very often when creating
modules in quick succession, which means that the mtime stays identical,
which then appears in comtype's case as random module import failures
when using a new COM object for the first time.
@snoopyjc
Copy link

snoopyjc commented May 4, 2019

Thank you!! This fixed my recent issue when I upgraded to Office 365!

@nanonyme
Copy link

nanonyme commented Sep 9, 2020

This is still very much a problem with this library and is causing random failures on Windows.

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 this pull request may close these issues.

(restricted user issue) ModuleNotFoundError: No module named 'comtypes.gen.stdole'
4 participants