Skip to content

Fix comInterfaces_sconscript to no longer fail on wrapper module creation - #10235

Merged
michaelDCurran merged 2 commits into
nvaccess:masterfrom
BabbageCom:comtypesImport
Sep 18, 2019
Merged

Fix comInterfaces_sconscript to no longer fail on wrapper module creation#10235
michaelDCurran merged 2 commits into
nvaccess:masterfrom
BabbageCom:comtypesImport

Conversation

@LeonarddeR

@LeonarddeR LeonarddeR commented Sep 17, 2019

Copy link
Copy Markdown
Collaborator

Link to issue number:

Fixes #10228

Summary of the issue:

Comtypes wrapper module creation sometimes fails as the Python import mechanism creates a cache of paths we can import from, and that cache doesn't like frequent updates. See also enthought/comtypes#172

Description of how this pull request fixes the issue:

Monkeypatch comtypes.client._generate._my_import to clear the importlib cache first. Make sure comtypes is monkeypatches in our scons environment.

It also simplifies the patch that changes the wrapper generation directory, i.e. it no longer fiddles with sys.modules. Testing revealed that this is no longer necessary. Code revealed that thit is now done by comtypes.client._generate._my_import .

Testing performed:

Tested as part of #10169 appveyor build. See also #10228

Known issues with pull request:

None

Change log entry:

None

@LeonarddeR
LeonarddeR marked this pull request as ready for review September 17, 2019 12:56

@michaelDCurran michaelDCurran left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think there would be any performance impact for this? no doubt importlib caching is there in Python3 for a reason, and if I understand correctly, any caching is dropped for every import of a comtypes COM interface. Could an alternative be that we only monkeypatch this for comInterfaces_sconscript? Or could this issue happen during NVDA running?

@LeonarddeR

Copy link
Copy Markdown
Collaborator Author

Do you think there would be any performance impact for this? no doubt importlib caching is there in Python3 for a reason, and if I understand correctly, any caching is dropped for every import of a comtypes COM interface.

I don't think it will have a very severe impact. Calling importlib.invalidate_caches doesn't have a noticeable delay, and if there is any impact, it is only at the start of NVDA.

Could an alternative be that we only monkeypatch this for comInterfaces_sconscript? Or could this issue happen during NVDA running?

Yes, I've seen this happening on an installed copy when trying to import an interface for which I did not have a wrapper yet.

@michaelDCurran
michaelDCurran merged commit e77dcbd into nvaccess:master Sep 18, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Sep 18, 2019
@LeonarddeR
LeonarddeR deleted the comtypesImport branch September 24, 2019 05:10
@LeonarddeR LeonarddeR added the BabbageWork Pull requests filed on behalf of Babbage B.V. label Oct 11, 2019
@lukaszgo1 lukaszgo1 mentioned this pull request Oct 3, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BabbageWork Pull requests filed on behalf of Babbage B.V.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Current master: SCons source faills for the first two runs

3 participants