Skip to content

Commit

Permalink
Fix #59, initialize and uninitialize COM for threading
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenetar committed Aug 8, 2021
1 parent 94e1ec0 commit d249f01
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions send2trash/plat_win_modern.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def send2trash(paths):
paths = [op.abspath(path) if not op.isabs(path) else path for path in paths]
# remove the leading \\?\ if present
paths = [path[4:] if path.startswith("\\\\?\\") else path for path in paths]
# Need to initialize the com before using
pythoncom.CoInitialize()
# create instance of file operation object
fileop = pythoncom.CoCreateInstance(
shell.CLSID_FileOperation, None, pythoncom.CLSCTX_ALL, shell.IID_IFileOperation,
Expand Down Expand Up @@ -65,3 +67,6 @@ def send2trash(paths):
# convert to standard OS error, allows other code to get a
# normal errno
raise OSError(None, error.strerror, path, error.hresult)
finally:
# Need to make sure we call this once fore every init
pythoncom.CoUninitialize()

0 comments on commit d249f01

Please sign in to comment.