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

Exception when multiple processes access COM objects with the same interface #1600

Closed
SReicheltPTV opened this issue Oct 26, 2020 · 0 comments · Fixed by #1601
Closed

Exception when multiple processes access COM objects with the same interface #1600

SReicheltPTV opened this issue Oct 26, 2020 · 0 comments · Fixed by #1601

Comments

@SReicheltPTV
Copy link
Contributor

When multiple processes access COM interfaces from Python, generating and importing modules for these interfaces sometimes fails. The effect is similar to #1595, but in contrast to that bug, it can be reproduced with a debugger as follows:

  1. Delete the gen_py folder.
  2. Create a Python file to access a COM server using EnsureDispatch:
    import win32com.client
    win32com.client.gencache.EnsureDispatch('<some COM server>')
    
  3. Place a breakpoint at the beginning of finish_writer in genpy.py.
  4. Run until the breakpoint is hit the second time.
  5. In another python instance, attempt to run the script completely.

Now the second script will try to write to the same temporary file as the first, which will fail.
So the second script should use a separate temporary file, but then genpy.py also needs to cope with the situation that the module has already been generated in the meantime.

Note that this it is not necessary for both scripts to access the same COM server; they merely need to access COM servers with the same interface. For this reason, we ran into this problem somewhat frequently when running tests in parallel, until we pre-generated everything using makepy.

This is actually an old problem that affects all versions of pywin32. Will submit a PR.

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 a pull request may close this issue.

1 participant