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

Hanging/Freezing when calling comtypes.client.CreateObject #507

Closed
rlaphoenix opened this issue Jan 22, 2024 · 14 comments
Closed

Hanging/Freezing when calling comtypes.client.CreateObject #507

rlaphoenix opened this issue Jan 22, 2024 · 14 comments

Comments

@rlaphoenix
Copy link

rlaphoenix commented Jan 22, 2024

This hasn't happened to me the last time I ran an exact bit of code. The only thing that changed was my Python version. I would have gone from I believe Python 3.10.7 to Python 3.11.7, where it now freezes. Some Windows updates likely went on through then as well.

I used venv via Python poetry and started with a clean venv with no result.

While I do call comtypes.client.CreateObject(...) it is actually freezing at the obj = comtypes.CoCreateInstance(...) line within it, and to be specific again, freezing at _ole32.CoCreateInstance(...) within that.

Environment:

Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] on win32
Installed as Admin to C:/Program Files/Python311
Python Poetry 1.6.1
Windows 11 Pro 23H2 22631.3007 on Windows Feature Experience Pack 1000.22681.1000.0

Debug Logs:

DEBUG:comtypes:CoInitializeEx(None, 2)
INFO:comtypes.client._code_cache:Imported existing <module 'comtypes.gen' from 'C:\\Users\\x\\Projects\\SubReDo\\.venv\\Lib\\site-packages\\comtypes\\gen\\__init__.py'>
INFO:comtypes.client._code_cache:Using writeable comtypes cache directory: 'C:\Users\x\Projects\SubReDo\.venv\Lib\site-packages\comtypes\gen'
DEBUG:comtypes.client:VideoReDoPro6.VideoReDoSilent -> {B91B711D-E21F-4800-8DC6-FAB87925E949}
DEBUG:comtypes.client:CoCreateInstance({B91B711D-E21F-4800-8DC6-FAB87925E949}, clsctx=None, interface=None
... It then hangs here
@junkmd
Copy link
Collaborator

junkmd commented Jan 22, 2024

Hi,

When upgrading from Python 3.10.7 to Python 3.11.7, please check if there have been any changes in the version for comtypes.
If you are using poetry, the locked version info might be recorded somewhere.

Moreover, you seem to be masking the arguments passed to CreateObject with ....
If you share the arguments with us, would it violate the NDA?
If not, please consider sharing it with the community.

@rlaphoenix
Copy link
Author

rlaphoenix commented Jan 22, 2024

I did not have any change in what release version of comtypes was used. I used v1.2.0 on Python 3.10, and tried both v1.2.0 and v1.2.1 on my current version of Python 3.11.

[[package]]
name = "comtypes"
version = "1.2.0"
description = "Pure Python COM package"
category = "main"
optional = false
python-versions = "*"
files = [
    {file = "comtypes-1.2.0-py2.py3-none-any.whl", hash = "sha256:26f261b1eed6972d5cdaa3af1fadb3fa76fc59877d0a1293835327a76573380d"},
    {file = "comtypes-1.2.0.zip", hash = "sha256:c8f2f0e995d73baf0bd899a948d62adeb9ab908c8270c66a67ff09dfcf4872b7"},
]

I can share yes, but I don't think it will be replicable here unless someone else has this software, which is why I neglected to list them.

obj = comtypes.client.CreateObject("VideoReDoPro6.VideoReDoSilent")

View line in my project

@junkmd
Copy link
Collaborator

junkmd commented Jan 23, 2024

Thanks for the infomation.

It is indeed that I do not have VideoReDo and I cannot run your script in my environment.
However, there may be someone in the community who is familiar with that COM library, or even if not, there may be someone who can find a clue from the relevant information.
It is important to know the details of the situation in order to solve such problems, so please do not hesitate to share information.

Please try to revert poetry settings to its previous state and see if the same script works.
If you succeeded with Python 3.10.7 and failed with Python 3.11.7 using the same comtypes==1.2.0, then perhaps we might have encountered an unknown regression or bug in the ctypes standard library.

Keep in mind, even if there is no problem with Python or comtypes, it is possible that Windows Update has changed the behavior of the COM library.

If this happens even after reverting the poetry setting, Windows Update may be the cause.

@rlaphoenix
Copy link
Author

rlaphoenix commented Jan 23, 2024

I've tried 3.10.11, 3.10.7, and 3.9.7. They all hang. I tried 1.2.1 and 1.2.0 on both.

Traceback (most recent call last):                                                                                                                                           
  File "C:\Users\x\Projects\SubReDo\subredo\videoredocom.py", line 18, in __init__
    vrd_silent = comtypes.client.CreateObject("VideoReDoPro6.VideoReDoSilent")  # check for v6 pro first
  File "C:\Users\x\Projects\SubReDo\.venv\lib\site-packages\comtypes\client\__init__.py", line 252, in CreateObject
    obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
  File "C:\Users\x\Projects\SubReDo\.venv\lib\site-packages\comtypes\__init__.py", line 935, in CoCreateInstance
    _ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
  File "_ctypes/callproc.c", line 997, in GetResult
OSError: [WinError -2146959355] Server execution failed

When I kill the VideoReDo process I get this error. I see another issue with a similar error: #198

I should also note asking the Developers of VideoReDo for assistance isn't unfortunately an option as the developer has unfortunately passed away some time ago.

@junkmd
Copy link
Collaborator

junkmd commented Jan 23, 2024

I think that Windows Update is probably the cause of this problem, after all.

I saw #198 during the inventory of issues I did when I became the maintainer of this project, but it had not been active for several years and I was not sure what the reporter was facing.
In hindsight, I'm starting to think that the author of #198 might have wanted to report "The combination of comtypes and Word is currently not available, probably due to a Windows Update".

It is unfortunate and sad that the COM library you want to use is not currently supported.

However, it may be one way to wait for the next Windows Update, like pywinauto/pywinauto#1350.
Or you may find a solution by contacting MS technical support.

@junkmd
Copy link
Collaborator

junkmd commented Jan 25, 2024

A newer build is being released after 22631.3007.

https://support.microsoft.com/en-us/topic/january-23-2024-kb5034204-os-builds-22621-3085-and-22631-3085-preview-7652acf2-56dc-430e-b8ef-ec8f56ec1028

If you could try this and let us know how it went, the community can use it as a reference on what to do in the future when something similar happens.

@rlaphoenix
Copy link
Author

It's still happening on 22631.3085

@junkmd
Copy link
Collaborator

junkmd commented Jan 31, 2024

Have you contacted MS technical support?

Also, in the VideoReDo user community, are there people who have encountered similar situations?

@junkmd
Copy link
Collaborator

junkmd commented Feb 26, 2024

Is there an update on this issue?

@rlaphoenix
Copy link
Author

I've tried many times since to try find out why, and I cannot figure out anything. I doubt asking Microsoft for support will do anything I've asked them before in live chat, call, and remote support for much simpler stuff and they can barely go through task manager.

@junkmd
Copy link
Collaborator

junkmd commented Feb 28, 2024

I think there might be developers using the VideoReDo COM interface, not limited to comtypes or Python. If such a community exists, it might be beneficial to share your situation with them.

I'm not sure that the error you're facing can be fixed by modifying the implementation of comtypes.
If you can attempt manipulating the VideoReDo COM interface in another library or a different programming language, please give it a try.

The results may provide clues to a solution.

@rlaphoenix
Copy link
Author

I dont know of any communities that really use it like how I do, other than the late dev.

However, trying to start it via PowerShell doesn't work, unless I set compatibility mode to Windows 8, which I then end up with a COMObject. But, trying to do anything with it makes it act like the $vrd object is now null, which is odd.

If I try to access it in Python interpreter directly it starts the process much like PowerShell did, but never ends/finishes the comtypes.client.CreateObject line so I can never run anything after like trying to get the program version number.

>>> import comtypes
>>> import comtypes.client
>>> comtypes.CoInitialize()
>>> vrd_silent = comtypes.client.CreateObject("VideoReDoPro6.VideoReDoSilent")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python311\Lib\site-packages\comtypes\client\__init__.py", line 252, in CreateObject
    obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\site-packages\comtypes\__init__.py", line 935, in CoCreateInstance
    _ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
  File "_ctypes/callproc.c", line 1000, in GetResult
OSError: [WinError -2146959355] Server execution failed

If I kill the process in task manager I get the above. Trying the same code but by saving to a .py script and calling it, does the exact same thing.

@rlaphoenix
Copy link
Author

rlaphoenix commented Feb 28, 2024

Ok, I don't know why at all. But, if I uninstall and reinstall VideoReDo, no luck. However, If I uninstall VideoReDo, search for and delete any and all possible ReDo or DRDSystems/DRD Systems related file from the system (not searching registry), and then reinstall, it works. I don't think it's a dud configuration/settings because it somehow still retained my settings even after all of this, so I presume settings are in the registry.

COM on Python shell:

$ python
Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import comtypes
>>> import comtypes.client
>>> comtypes.CoInitialize()
>>> vrd_silent = comtypes.client.CreateObject("VideoReDoPro6.VideoReDoSilent")
>>> vrd_silent.VRDInterface.ProgramGetVersionNumber
'6.93.7.836 - Mar 23 2022'

COM in my project (working):

image

Either way, doing that seemed to fix it, meaning this wasn't a comtypes issue in the end. Sorry to bother you, this can be closed. Hopefully, it won't occur again.

@junkmd
Copy link
Collaborator

junkmd commented Feb 28, 2024

Glad to hear that your problem has been resolved.

If I uninstall VideoReDo, search for and delete any and all possible ReDo or DRDSystems/DRD Systems related file from the system (not searching registry), and then reinstall, it works.

I think there are common problems in the world that can be resolved in a way like this.
I have come across cases where proprietary software with complex dependencies and clean-up tools for re-installing are provided at the same time.

It's not hard to imagine such complex dependencies related to graphics and sounds within VideoReDo.

Sorry to bother you, this can be closed.

Never mind.
I think this can serve as a reference for the workflow to be followed when the community encounters similar issues again.

@junkmd junkmd closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2024
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

No branches or pull requests

2 participants