New submission from Michael Allen:

Modifying a file while getting a stacktrace across multiple threads causes 
linecache's cache to bust and del to be called on the global cache variable. 
This is not thread safe and raises a KeyError.

Reproducible with,

import threading
import traceback

def main():
    with open(__file__, 'a') as fp:
        fp.write(' ')
        traceback.format_stack()

threads = [
    threading.Thread(target=main)
    for i in range(100)
]
map(lambda t: t.start(), threads)
map(lambda t: t.join(), threads)

I see the following error,

Exception in thread Thread-56:
Traceback (most recent call last):
  File "/Users/me/.pyenv/versions/2.7.10/lib/python2.7/threading.py", line 810, 
in __bootstrap_inner
    self.run()
  File "/Users/me/.pyenv/versions/2.7.10/lib/python2.7/threading.py", line 763, 
in run
    self.__target(*self.__args, **self.__kwargs)
  File "test.py", line 7, in main
    traceback.format_stack()
  File "/Users/me/.pyenv/versions/2.7.10/lib/python2.7/traceback.py", line 279, 
in format_stack
    return format_list(extract_stack(f, limit))
  File "/Users/me/.pyenv/versions/2.7.10/lib/python2.7/traceback.py", line 305, 
in extract_stack
    linecache.checkcache(filename)
  File "/Users/me/.pyenv/versions/2.7.10/lib/python2.7/linecache.py", line 69, 
in checkcache
    del cache[filename]
KeyError: 'test.py'

Possible solution is to ignore KeyError on del cache[filename].

----------
components: Library (Lib)
messages: 256469
nosy: Michael Allen
priority: normal
severity: normal
status: open
title: multithreading traceback KeyError when modifying file
type: crash
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25872>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com


Reply via email to