Author Nicolas Savoire
Recipients Nicolas Savoire
Date 2016-12-14.10:49:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1481712564.52.0.530922236321.issue28969@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2016-12-14 10:49:24Nicolas Savoiresetrecipients: + Nicolas Savoire
2016-12-14 10:49:24Nicolas Savoiresetmessageid: <1481712564.52.0.530922236321.issue28969@psf.upfronthosting.co.za>
2016-12-14 10:49:24Nicolas Savoirelinkissue28969 messages
2016-12-14 10:49:24Nicolas Savoirecreate