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
I'm using my own implementation of the memoize by shelve module. In the attachment, there are 2 simple test cases which pass but the console there are a lot of messages like that:
Exception ignored in: <function Shelf.__del__ at 0x0000023202F363A0>
Traceback (most recent call last):
File "C:\Miniconda2\envs\38_common\lib\shelve.py", line 162, in __del__self.close()
File "C:\Miniconda2\envs\38_common\lib\shelve.py", line 144, in closeself.sync()
File "C:\Miniconda2\envs\38_common\lib\shelve.py", line 172, in syncself.dict.sync()
File "C:\Miniconda2\envs\38_common\lib\dbm\dumb.py", line 129, in _commitwithself._io.open(self._dirfile, 'w', encoding="Latin-1") as f:
PermissionError: [Errno 13] Permission denied: 'C:\\project\\tests\\test_memoize_tmp_t5tai08p\\memoize_test_file.dat.dir'
Exception ignored in: <function _Database.close at 0x0000023202EF9040>
Traceback (most recent call last):
File "C:\Miniconda2\envs\38_common\lib\dbm\dumb.py", line 274, in closeself._commit()
File "C:\Miniconda2\envs\38_common\lib\dbm\dumb.py", line 129, in _commitwithself._io.open(self._dirfile, 'w', encoding="Latin-1") as f:
PermissionError: [Errno 13] Permission denied: 'C:\\project\\tests\\test_memoize_tmp_t5tai08p\\memoize_test_file.dat.dir'
Basically, the main issue can be explained like that - Python dbm.dumb._Database should maintain self._modified the attribute in the right way(set it to False) after the _commit method.
Later I will try to make changes in the dbm.dumb module and run Python internal tests for that modification to see any regression, if not will add PR here.
It is not a bug. If you do not close the database explicitly, it will be implicitly closed in the __del__() method. And this happens when the local variable memoize is rebound, which happens only after a new database referring to the same files is opened. Opening multiple databases that use the same files is not supported.
But it is good idea to mark the database as unmodified after synchronization or creation and avoid any writing in __del__() if there was no modifications since that moment. It helps to save data, even if the use of the database is not perfect.
Activity
libbkmz commentedon Jan 3, 2020
I'm using my own implementation of the memoize by shelve module. In the attachment, there are 2 simple test cases which pass but the console there are a lot of messages like that:
Basically, the main issue can be explained like that - Python dbm.dumb._Database should maintain self._modified the attribute in the right way(set it to False) after the _commit method.
Later I will try to make changes in the dbm.dumb module and run Python internal tests for that modification to see any regression, if not will add PR here.
pythongh-83383: Always mark the dbm.dumb database as unmodified after…
serhiy-storchaka commentedon Jan 25, 2024
It is not a bug. If you do not close the database explicitly, it will be implicitly closed in the
__del__()method. And this happens when the local variablememoizeis rebound, which happens only after a new database referring to the same files is opened. Opening multiple databases that use the same files is not supported.But it is good idea to mark the database as unmodified after synchronization or creation and avoid any writing in
__del__()if there was no modifications since that moment. It helps to save data, even if the use of the database is not perfect.gh-83383: Always mark the dbm.dumb database as unmodified after open(…
pythongh-83383: Always mark the dbm.dumb database as unmodified after…
pythongh-83383: Always mark the dbm.dumb database as unmodified after…