Again ensure comtypes calls raise CallCancelled when cancelled by watchdog - #10279
Merged
Conversation
…s.WINFUNCTYPE has been replaced with a cancellable version.
… much for what scons needs, and fails as it tries to import core. Rather, just do the specific comtypes.client._generate monkeypatch in comInterfaces_sconscript where it is actually needed.
LeonarddeR
approved these changes
Sep 26, 2019
LeonarddeR
left a comment
Collaborator
There was a problem hiding this comment.
I'm very sorry for reintroducing this regression.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue number:
Fixes #10276
Summary of the issue:
In pr #9795 code was added to ensure that CallCancel was raised rather than COMError when a comtypes call was cancelled by watchdog in Python3. In Python2 we did this by overriding
__call__on _ctypes.COMError, however in Python3 this is read-only and can't be done. Therefore in pr #9795 we monkeypatched ctypes.WINFUNCTYPE to return a class with a custom__call__that converted COMError to CallCancelled if it was a cancelled call. We monkeypatched this just before comtypes was imported for the first time and then removed it once the import was done, there by ensuring that comtypes got our custom WINFUNCTYPE.However, in pr #10235, a comtypes.client module was imported at the top of comtypesMonekyPatches.py which forced comtypes to be imported before the WINFUNCTYPE monkeypatching could occur, therefore, comtypes calls no longer would raise CallCancelled when cancelled via watchdog.
Description of how this pull request fixes the issue:
In comtypesMonkeyPatches.py: Moved the import of comtypes.client._generate down to where it is actually needed, below the monkeypatching of WINFUNCTYPE and the initial import of comtypes.
Extra comments have been also added above and below where it is unsafe to import any comtypes modules.
This change did however break builds on appveyor because when comInterfaces_sonscript tried to generate interfaces, our monkeypatched WINFUNCTYPE kicked into action, due to comtypesMonkeyPatches being imported by sconsctruct, and then in some COMErrors further exceptions were raised because core.CallCancelled could not be imported.
Therefore, rather than importing comtypesMonkeypatches in sonstruct, we now just manually do the comtypes.client._generate monkeypatch in comInterfaces_sconscript, specifically where it is needed.
Testing performed:
Performed testcase from issue #10276 and CallCancelled is again correctly raised.
Known issues with pull request:
None.
Change log entry:
None.