Author Michael Allen
Recipients Michael Allen
Date 2015-12-15.17:21:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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(' ')

threads = [
    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/", line 810, in __bootstrap_inner
  File "/Users/me/.pyenv/versions/2.7.10/lib/python2.7/", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "", line 7, in main
  File "/Users/me/.pyenv/versions/2.7.10/lib/python2.7/", line 279, in format_stack
    return format_list(extract_stack(f, limit))
  File "/Users/me/.pyenv/versions/2.7.10/lib/python2.7/", line 305, in extract_stack
  File "/Users/me/.pyenv/versions/2.7.10/lib/python2.7/", line 69, in checkcache
    del cache[filename]
KeyError: ''

Possible solution is to ignore KeyError on del cache[filename].
Date User Action Args
2015-12-15 17:21:04Michael Allensetrecipients: + Michael Allen
2015-12-15 17:21:04Michael Allensetmessageid: <>
2015-12-15 17:21:04Michael Allenlinkissue25872 messages
2015-12-15 17:21:04Michael Allencreate