Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1f44914

Browse files
committed
Merged revisions 78137 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r78137 | r.david.murray | 2010-02-10 17:42:04 -0500 (Wed, 10 Feb 2010) | 8 lines Issue 7835: Shelve's __del__ method calls its close method, and its close method refers to an identifier in the global module namespace. This means that when __del__ is called during interpreter shutdown (if, for example, the calling program still has a pointer to the shelf), sometimes that global identifier would wind up being None, causing mysterious 'ignored' exceptions. This patch checks for the possible None value first before using the global, thus avoiding the error messages. ........
1 parent 0b581e5 commit 1f44914

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/shelve.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ def close(self):
136136
self.dict.close()
137137
except AttributeError:
138138
pass
139-
self.dict = _ClosedDict()
139+
# _ClosedDict can be None when close is called from __del__ during shutdown
140+
if _ClosedDict is None:
141+
self.dict = None
142+
else:
143+
self.dict = _ClosedDict()
140144

141145
def __del__(self):
142146
if not hasattr(self, 'writeback'):

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ C-API
242242
Library
243243
-------
244244

245+
- Issue #7835: shelve should no longer produce mysterious warnings during
246+
interpreter shutdown.
247+
245248
- Issue #2746: Don't escape ampersands and angle brackets ("&", "<", ">")
246249
in XML processing instructions and comments. These raw characters are
247250
allowed by the XML specification, and are necessary when outputting e.g.

0 commit comments

Comments
 (0)