Author mschmitzer
Recipients mschmitzer
Date 2015-01-08.13:02:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The way the fnmatch module uses its regex cache is not threadsafe. When multiple threads use the module in parallel, a race condition between retrieving a - presumed present - item from the cache and clearing the cache (because the maximum size has been reached) can lead to KeyError being raised.

The attached script demonstrates the problem. Running it will (eventually) yield errors like the following.

Exception in thread Thread-10:
Traceback (most recent call last):
  File "/usr/lib/python2.7/", line 810, in __bootstrap_inner
  File "/usr/lib/python2.7/", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "", line 12, in run
    fnmatch.fnmatchcase(name, pat)
  File "/home/marc/.venv/modern/lib/python2.7/", line 79, in fnmatchcase
    return _cache[pat].match(name) is not None
KeyError: 'lYwrOCJtLU'
Date User Action Args
2015-01-08 13:02:17mschmitzersetrecipients: + mschmitzer
2015-01-08 13:02:17mschmitzersetmessageid: <>
2015-01-08 13:02:17mschmitzerlinkissue23191 messages
2015-01-08 13:02:17mschmitzercreate