mirror of
https://github.com/python/cpython.git
synced 2025-08-23 10:16:01 +00:00
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.
This commit is contained in:
parent
97e1568325
commit
d72ea60521
1 changed files with 3 additions and 3 deletions
|
@ -71,10 +71,10 @@ def checkcache(filename=None):
|
||||||
try:
|
try:
|
||||||
stat = os.stat(fullname)
|
stat = os.stat(fullname)
|
||||||
except OSError:
|
except OSError:
|
||||||
del cache[filename]
|
cache.pop(filename, None)
|
||||||
continue
|
continue
|
||||||
if size != stat.st_size or mtime != stat.st_mtime:
|
if size != stat.st_size or mtime != stat.st_mtime:
|
||||||
del cache[filename]
|
cache.pop(filename, None)
|
||||||
|
|
||||||
|
|
||||||
def updatecache(filename, module_globals=None):
|
def updatecache(filename, module_globals=None):
|
||||||
|
@ -84,7 +84,7 @@ def updatecache(filename, module_globals=None):
|
||||||
|
|
||||||
if filename in cache:
|
if filename in cache:
|
||||||
if len(cache[filename]) != 1:
|
if len(cache[filename]) != 1:
|
||||||
del cache[filename]
|
cache.pop(filename, None)
|
||||||
if not filename or (filename.startswith('<') and filename.endswith('>')):
|
if not filename or (filename.startswith('<') and filename.endswith('>')):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue