-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
Extracting a corrupt 7z file and try to delete it will cause the PermissionError in windows #597
Comments
You can read the suggestion what AI explained the situation. Why doesn’t Windows unlock the file immediately?Even though your program calls 1. Delayed or Buffered Writes
Example in Python:with open("example.txt", "w") as f:
f.write("Hello, World!")
f.flush() # Ensures everything is written immediately.
# The file will still be properly closed and unlocked. 2. Antivirus or Backup Software Scanning
3. Multiple File Handles (By Accident)
Example of an issue:f1 = open("example.txt", "w")
f2 = open("example.txt", "r") # Oops! Now two handles are open.
f1.close() # Only one is closed; the other is still open.
# The file is still locked because f2 is open.
4. Pending OS Operations or File System Latency
Summary and Best Practices
By keeping these points in mind, you can avoid file-locking issues and ensure your programs behave as expected on Windows! |
This may be happened because
def __exit__(self, exc_type, exc_val, exc_tb):
self.close()
def _fpclose(self) -> None:
assert self._fileRefCnt > 0
self._fileRefCnt -= 1
if not self._fileRefCnt and not self._filePassed:
self.fp.close()
def close(self):
"""Flush all the data into archive and close it.
When close py7zr start reading target and writing actual archive file.
"""
if "w" in self.mode:
self._write_flush()
if "a" in self.mode:
self._write_flush()
if "r" in self.mode:
if self.reporterd is not None:
self.q.put_nowait(None)
self.reporterd.join(1)
if self.reporterd.is_alive():
raise InternalError("Progress report thread terminate error.")
self.reporterd = None
self._fpclose()
self._var_release() |
|
assert self._fileRefCnt > 0
self._fileRefCnt -= 1
if not self._fileRefCnt and This part may cause the unclosed status. |
When I’m extracting a particular corrupted 7z file, I get the PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: ‘corrupt.7z’. This error only occurs with this corrupted file. When I test with other random invalid 7z files, the error does not occur.
Because the file is 80MB, I can't upload it to github, here is the google drive link
The text was updated successfully, but these errors were encountered: