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

Use instead of coinitialize #51966

merged 1 commit into from Mar 5, 2019


Copy link

commented Mar 5, 2019

What does this PR do?

Use salt.utils.winapi.Com() instead of pythoncom.CoInitialize() where possible. salt.utils.winapi.Com() is a wrapper around CoInitialize that will clean up after itself.

What issues does this PR fix or reference?

May help with #51027
Less likely to help with #51793 as it seems to be more of a locale issue

Tests written?

Yes (fixed)

Commits signed with GPG?


dwoz approved these changes Mar 5, 2019
@dwoz dwoz merged commit da815ba into saltstack:2018.3 Mar 5, 2019
10 checks passed
10 checks passed
WIP Ready for review
continuous-integration/jenkins/pr-merge This commit looks good
jenkins/pr/docs The docs job has passed
jenkins/pr/lint Python lint test has passed
jenkins/pr/py2-centos-7 The py2-centos-7 job has passed
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has passed
jenkins/pr/py2-windows-2016 The py2-windows-2016 job has passed
jenkins/pr/py3-centos-7 The py3-centos-7 job has passed
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has passed
jenkins/pr/py3-windows-2016 The py3-windows-2016 job has passed
@twangboy twangboy deleted the twangboy:use_winapi_com branch Mar 5, 2019

This comment has been minimized.

Copy link

commented on salt/modules/ in a38300b Jul 11, 2019

@twangboy - does these things work?

Once you get out of the context of with salt.utils.winapi.Com(), is conn still valid, because it will in the Com class, on the exit method (which happens when you get out of the with block), you do a pythoncom.CoUninitialize().

I think once you add the with context, you should put everything inside (returns too).

And BTW, I do see these traces on a machine box:
File "C:\Program Files\National Instruments\Shared\salt-minion\bin\lib\site-packages\salt\modules\", line 569, in get_computer_desc
desc = get_system_info()['description']
File "C:\Program Files\National Instruments\Shared\salt-minion\bin\lib\site-packages\salt\modules\", line 520, in get_system_info
system = conn.Win32_OperatingSystem()[0]
File "C:\Program Files\National Instruments\Shared\salt-minion\bin\lib\site-packages\", line 1147, in getattr
return getattr (self._namespace, attribute)
File "C:\Program Files\National Instruments\Shared\salt-minion\bin\lib\site-packages\win32com\client\", line 527, in getattr
raise AttributeError("%s.%s" % (self.username, attr))
AttributeError: winmgmts:.Win32_OperatingSystem
2019-07-11 13:40:00,791 [salt.loader :791 ][CRITICAL][11628] Failed to load grains defined in grain file nisysmgmt.nisysmgmt_data in function <function nisysmgmt_data at 0x00000104AAD37158>, error:
Traceback (most recent call last):
File "C:\Program Files\National Instruments\Shared\salt-minion\bin\lib\site-packages\", line 1145, in getattr
return self._cached_classes (attribute)
File "C:\Program Files\National Instruments\Shared\salt-minion\bin\lib\site-packages\", line 1156, in _cached_classes
self._classes_map[class_name] = _wmi_class (self, self._namespace.Get (class_name))
File "", line 3, in Get
File "C:\Program Files\National Instruments\Shared\salt-minion\bin\lib\site-packages\win32com\client\", line 287, in ApplyTypes
result = self.oleobj.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'SWbemServicesEx', None, None, 0, -2147417848), None)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.