Skip to content

Again ensure comtypes calls raise CallCancelled when cancelled by watchdog - #10279

Merged
michaelDCurran merged 3 commits into
masterfrom
i10276
Sep 26, 2019
Merged

Again ensure comtypes calls raise CallCancelled when cancelled by watchdog #10279
michaelDCurran merged 3 commits into
masterfrom
i10276

Conversation

@michaelDCurran

@michaelDCurran michaelDCurran commented Sep 26, 2019

Copy link
Copy Markdown
Member

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.

…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 LeonarddeR left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm very sorry for reintroducing this regression.

@michaelDCurran
michaelDCurran merged commit 05fb329 into master Sep 26, 2019
@nvaccessAuto nvaccessAuto added this to the 2019.3 milestone Sep 26, 2019
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.

When getting a COM attribute using dynamic dispatch and the call is canceled, the original COMError is raised instead of watchdog.CallCancelled

3 participants