[New-bugs-announce] [issue28969] fnmatch is not threadsafe

Nicolas Savoire report at bugs.python.org
Wed Dec 14 05:49:24 EST 2016


New submission from Nicolas Savoire:

With python3.5, fnmatch appears not to be thrad safe. It fails with the following exception:

Traceback (most recent call last):
  File "test.py", line 18, in <module>
    f.result()
  File "/opt/anaconda3/lib/python3.5/concurrent/futures/_base.py", line 405, in result
    return self.__get_result()
  File "/opt/anaconda3/lib/python3.5/concurrent/futures/_base.py", line 357, in __get_result
    raise self._exception
  File "/opt/anaconda3/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "test.py", line 12, in foo
    fnmatch(ref, s)
  File "/opt/anaconda3/lib/python3.5/fnmatch.py", line 36, in fnmatch
    return fnmatchcase(name, pat)
  File "/opt/anaconda3/lib/python3.5/fnmatch.py", line 70, in fnmatchcase
    match = _compile_pattern(pat)
KeyError: ('SXJ8WZ9F7Z', <class 'str'>)

Here is a minimal example reproducing the issue:

import concurrent.futures
from fnmatch import fnmatch
import random
import string

def str_generator(size=10, chars=string.ascii_uppercase + string.digits):
   return ''.join(random.choice(chars) for _ in range(size))


def foo(strs, ref):
    for s in strs:
        fnmatch(ref, s)

some_strings = [str_generator() for _ in range(500)]
with concurrent.futures.ThreadPoolExecutor() as executor:
    futures = [executor.submit(foo, some_strings, some_strings[0]) for _ in range(8)]
    for f in futures:
        f.result()



$ python3 --version
Python 3.5.2 :: Anaconda 4.2.0 (64-bit)

----------
components: Library (Lib)
files: test.py
messages: 283185
nosy: Nicolas Savoire
priority: normal
severity: normal
status: open
title: fnmatch is not threadsafe
type: crash
versions: Python 3.5
Added file: http://bugs.python.org/file45895/test.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28969>
_______________________________________


More information about the New-bugs-announce mailing list