Skip to content

Commit d72ea60

Browse files
authored
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.
1 parent 97e1568 commit d72ea60

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Lib/linecache.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ def checkcache(filename=None):
7171
try:
7272
stat = os.stat(fullname)
7373
except OSError:
74-
del cache[filename]
74+
cache.pop(filename, None)
7575
continue
7676
if size != stat.st_size or mtime != stat.st_mtime:
77-
del cache[filename]
77+
cache.pop(filename, None)
7878

7979

8080
def updatecache(filename, module_globals=None):
@@ -84,7 +84,7 @@ def updatecache(filename, module_globals=None):
8484

8585
if filename in cache:
8686
if len(cache[filename]) != 1:
87-
del cache[filename]
87+
cache.pop(filename, None)
8888
if not filename or (filename.startswith('<') and filename.endswith('>')):
8989
return []
9090

0 commit comments

Comments
 (0)