Skip to content

Commit b86636b

Browse files
authored
[3.8] bpo-25872: Fix KeyError in linecache when multithreaded (GH-18007) (GH-20092)
Backporting to 3.8 and adding a NEWS item (I should have added one to the master branch -- oh well).
1 parent 6381ee0 commit b86636b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Lib/linecache.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def checkcache(filename=None):
7373
try:
7474
stat = os.stat(fullname)
7575
except OSError:
76-
del cache[filename]
76+
cache.pop(filename, None)
7777
continue
7878
if size != stat.st_size or mtime != stat.st_mtime:
79-
del cache[filename]
79+
cache.pop(filename, None)
8080

8181

8282
def updatecache(filename, module_globals=None):
@@ -86,7 +86,7 @@ def updatecache(filename, module_globals=None):
8686

8787
if filename in cache:
8888
if len(cache[filename]) != 1:
89-
del cache[filename]
89+
cache.pop(filename, None)
9090
if not filename or (filename.startswith('<') and filename.endswith('>')):
9191
return []
9292

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`linecache` could crash with a :exc:`KeyError` when accessed from multiple threads.
2+
Fix by Michael Graczyk.

0 commit comments

Comments
 (0)