You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation for os.remove states On Windows, attempting to remove a file that is in use causes an exception to be raised; but doesnt mention the exception type being returned. The exception type is PermissionError. It should be documented
This wording is slightly off. The docs should say that trying to remove an in-use file "may" cause an exception to be raised, while in some cases it may not. For example:
In this case, the flag O_TEMPORARY opens the file with DELETE access and FILE_SHARE_DELETE share mode. Thus os.remove() is allowed to reopen the file with DELETE access.
OTOH, opening via builtin open() doesn't share delete access, so trying to reopen the file with delete access fails with the Windows error code ERROR_SHARING_VIOLATION (32), and Python raises PermissionError.
Activity
eryksun commentedon Jul 8, 2024
This wording is slightly off. The docs should say that trying to remove an in-use file "may" cause an exception to be raised, while in some cases it may not. For example:
In this case, the flag
O_TEMPORARYopens the file withDELETEaccess andFILE_SHARE_DELETEshare mode. Thusos.remove()is allowed to reopen the file withDELETEaccess.OTOH, opening via builtin
open()doesn't share delete access, so trying to reopen the file with delete access fails with the Windows error codeERROR_SHARING_VIOLATION(32), and Python raisesPermissionError.pythongh-121509: Document which error os.remove() raises on Windows f…
gh-121509: Clarify that os.remove may raise PermissionError on Windows (