summaryrefslogtreecommitdiffstats
path: root/Lib/linecache.py
diff options
context:
space:
mode:
authorMichael Graczyk <mgraczyk@users.noreply.github.com>2020-05-13 22:41:57 (GMT)
committerGitHub <noreply@github.com>2020-05-13 22:41:57 (GMT)
commitd72ea605218bbee6ae46648997d9bb76d0fba460 (patch)
tree17f485c685bed468a44e2ed27e3c3e4b639ab805 /Lib/linecache.py
parent97e1568325e4d8eff2fc80eeb174b3f3e5d1c350 (diff)
downloadcpython-d72ea605218bbee6ae46648997d9bb76d0fba460.zip
cpython-d72ea605218bbee6ae46648997d9bb76d0fba460.tar.gz
cpython-d72ea605218bbee6ae46648997d9bb76d0fba460.tar.bz2
issue-25872: Fix KeyError using linecache from multiple threads (GH-18007)
The crash that this fixes occurs when using traceback and other modules from multiple threads; del cache[filename] can raise a KeyError.
Diffstat (limited to 'Lib/linecache.py')
-rw-r--r--Lib/linecache.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/linecache.py b/Lib/linecache.py
index ddd0abf..fa5dbd0 100644
--- a/Lib/linecache.py
+++ b/Lib/linecache.py
@@ -71,10 +71,10 @@ def checkcache(filename=None):
try:
stat = os.stat(fullname)
except OSError:
- del cache[filename]
+ cache.pop(filename, None)
continue
if size != stat.st_size or mtime != stat.st_mtime:
- del cache[filename]
+ cache.pop(filename, None)
def updatecache(filename, module_globals=None):
@@ -84,7 +84,7 @@ def updatecache(filename, module_globals=None):
if filename in cache:
if len(cache[filename]) != 1:
- del cache[filename]
+ cache.pop(filename, None)
if not filename or (filename.startswith('<') and filename.endswith('>')):
return []