8000 [3.8] bpo-25872: Fix KeyError using linecache from multiple threads (… · akuchling/cpython@45240f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 45240f6

Browse files
mgraczykakuchling
authored andcommitted
[3.8] bpo-25872: Fix KeyError using linecache from multiple threads (pythonGH-18007)
The crash that this fixes occurs when using traceback and other modules from multiple threads; del cache[filename] can raise a KeyError. (cherry picked from commit d72ea60) Co-authored-by: Michael Graczyk <mgraczyk@users.noreply.github.com>
1 parent 35b8a4d commit 45240f6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Lib/linecache.py

Lines changed: 3 additions & 3 deletions
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

0 commit comments

Comments
 (0)
0