]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
issue-25872: Fix KeyError using linecache from multiple threads (GH-18007)
authorMichael Graczyk <mgraczyk@users.noreply.github.com>
Wed, 13 May 2020 22:41:57 +0000 (17:41 -0500)
committerGitHub <noreply@github.com>
Wed, 13 May 2020 22:41:57 +0000 (18:41 -0400)
The crash that this fixes occurs when using traceback and other modules from multiple threads;
del cache[filename] can raise a KeyError.

Lib/linecache.py

index ddd0abf2cf01d9e3a8dea236da60c02a8a627c0f..fa5dbd09eab8693a0a50fbf98ce2d1ee59b9404c 100644 (file)
@@ -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 []