Closed eblis closed 3 months ago
@eblis please try the development branch code
The move operation is still prevented with permission error. I think you need to close more than just the file.
We tried with the following changes and then it started working. Is there any downside to closing everything, calling close()
on the MDF object, not only the _file
?
- except:
- if self._file:
- self._file.close()
- raise
+ except:
+ self.close()
+ raise
new commit
This works
Python version
Asammdf 7.4.2 Python 3.9 and 3.11
Code
MDF version
4.10
Code snippet
Traceback
I don't have a traceback as I debugged this issue on a colleague's machine, but I can show you the call trail.
Description
Asammdf keeps a file open after it has finished attempting to read from it (and failed with an exception), and we cannot access the file to move it even after asammdf object is out of scope. And since the asammdf object is out of scope we cannot manually try to close the file with
mdf_obj.close()
asmdf_obj
isn't defined anymore.We have an MDF file with 4.10 version, around 2GB in size which throws an exception in MDF.init() which has 2 issues:
with
statement cannot be used for such files, as it never enters the context manager, since the__init__()
function crashes before__enter__
has a chance to be called. Since__enter__
is never called, nor will__exit__
be called so there's no way for MDF object to close itself automatically.__init__
has crashed with an exception, preventing anyone else from opening the file for writing or from moving the file to another location.the
with MDF(file_path) as mdf_obj:
statement calls are like this:MDF.__init__()
is called, hereMDF4.__init__()
is called, herewith
statement never finishes executing (context manager never engages). If we didn't have thetry/catch
block it would raise the exception to the calling method__enter__
was never called, nor will__exit__
be called, so the MDF file has openedfile_path
and never closed it at this point.move_file(file_path, "some/other/folder")
fails with permission error as the file_path is still kept open bymdf_obj
, even thoughmdf_obj
is no longer defined and cannot be used in code.