send2trash function failed to delete a directory with unknown error
This function is referred in Jupyter server folder deletion logic. We observed the error in jupyterlab app and here in this description we try to simplify the scenario and reproduce it in a windows command prompt.
In python interpreter, we import the send2trash:
from send2trash import send2trash
And run this code line, deleting the directory:
send2trash('C:\\Users\\traveler\\AppData\\Local\\projects\\Untitled Folder')
In this case the "Untitled Folder" is newly created under a jlabapp project and there is a newly created ipynb file in it, it failed to delete "Untitled Folder" and throws message:
>>> send2trash('C:\Users\traveler\AppData\Local\projects\Untitled Folder') Traceback (most recent call last): File "C:\Users\traveler\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\send2trash\plat_win_modern.py", line 61, in send2trash result = fileop.PerformOperations() pywintypes.com_error: (-2144927705, 'OLE error 0x80270027', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "
", line 1, in File "C:\Users\traveler\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\send2trash\plat_win_modern.py", line 69, in send2trash raise OSError(None, error.strerror, path, error.hresult) OSError: [WinError -2144927705] OLE error 0x80270027: 'C:\Users\traveler\AppData\Local\projects\Untitled Folder'
However, when we close the project tab and reopen it. The above code line (exactly the same func and path) works and was able to delete "Untitled Folder".
Watching "Untitled Folder" in File Explorer and it seems there is no visible difference between the above two cases.
Best I can find for that error code is possibly a "sharing violation" so there might have been something else that had been accessing that folder at the time. Is it very reproducible, does it happen every time?
Yes it is reproducible and happens every time. Only happens to .ipynb file.