[Python-checkins] issue-25872: Fix KeyError using linecache from multiple threads (GH-18007)

Michael Graczyk webhook-mailer at python.org
Wed May 13 18:42:06 EDT 2020


https://github.com/python/cpython/commit/d72ea605218bbee6ae46648997d9bb76d0fba460
commit: d72ea605218bbee6ae46648997d9bb76d0fba460
branch: master
author: Michael Graczyk <mgraczyk at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-05-13T18:41:57-04:00
summary:

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.

files:
M Lib/linecache.py

diff --git a/Lib/linecache.py b/Lib/linecache.py
index ddd0abf2cf01d..fa5dbd09eab86 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 []
 



More information about the Python-checkins mailing list