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

Fix Windows compatibility with multithreading #59

Closed
wants to merge 1 commit into from
Closed

Fix Windows compatibility with multithreading #59

wants to merge 1 commit into from

Conversation

dolfinus
Copy link

Hi.

I've faced with some tests of Jupyterhub Notebook repo are failing:

Traceback (most recent call last):
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tornado\web.py", line 1704, in _execute
    result = await result
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tornado\gen.py", line 234, in wrapper
    yielded = ctx_run(next, result)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\tornado\gen.py", line 162, in _fake_ctx_run
    return f(*args, **kw)
  File "D:\a\notebook\notebook\notebook\services\contents\handlers.py", line 237, in delete
    yield maybe_future(cm.delete(path))
  File "D:\a\notebook\notebook\notebook\services\contents\manager.py", line 279, in delete
    self.delete_file(path)
  File "D:\a\notebook\notebook\notebook\services\contents\filemanager.py", line 533, in delete_file
    send2trash(os_path)
  File "c:\hostedtoolcache\windows\python\3.6.8\x64\lib\site-packages\send2trash\plat_win_modern.py", line 31, in send2trash
    shell.CLSID_FileOperation, None, pythoncom.CLSCTX_ALL, shell.IID_IFileOperation,
pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)

According to https://stackoverflow.com/questions/37258257/why-does-this-script-not-work-with-threading-python, it is important to call .CoInitialize() method to allow win32 API calls in multithread mode.

@arsenetar
Copy link
Owner

When I look into the information on .CoInitialize() I see that CoUninitialize() should be called for each call, this is shown in the example in the email thread: https://mail.python.org/pipermail/python-win32/2008-June/007788.html. I need to look into understanding this a bit more but that seems to be what the Microsoft COM documentation suggests as well at https://docs.microsoft.com/en-us/windows/win32/api/objbase/nf-objbase-coinitialize and https://docs.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-couninitialize.

@arsenetar arsenetar closed this in d249f01 Aug 8, 2021
@dolfinus
Copy link
Author

dolfinus commented Aug 8, 2021

Sorry, I've missed a notification about your comment. Thank you for merging a fix!

@dolfinus
Copy link
Author

dolfinus commented Aug 8, 2021

Could you please release a fixed version?

@arsenetar
Copy link
Owner

@dolfinus 1.8.0 is now pushed.

@dolfinus
Copy link
Author

dolfinus commented Aug 9, 2021

Thank you, tests have been passed successfully:
https://github.com/dolfinus/notebook/runs/3278236460?check_suite_focus=true

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.

2 participants