Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4042

ExtractionError when using accelerated thrift in a multiprocess test



    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.10.0
    • 0.11.0
    • Python - Library
    • None


      We recently switched to thrift 0.10.0 with accelerated protocols and started seeing ExtractionError being sporadically raised in tests that use the accelerated protocols (fastbinary module) and multiprocessing module. Example traceback:

      Traceback (most recent call last):
        File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
          "__main__", fname, loader, pkg_name)
        File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
          exec code in run_globals
        File "/tmp/thrift-4042/thrift4042.py", line 15, in <module>
        File "/tmp/thrift-4042/thrift4042.py", line 9, in load_fastbinary
          return TCompactProtocolAccelerated(None, fallback=False)
        File "build/bdist.linux-x86_64/egg/thrift/protocol/TCompactProtocol.py", line 449, in __init__
        File "build/bdist.linux-x86_64/egg/thrift/protocol/fastbinary.py", line 7, in <module>
        File "build/bdist.linux-x86_64/egg/thrift/protocol/fastbinary.py", line 4, in __bootstrap__
        File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1203, in resource_filename
          self, resource_name
        File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1715, in get_resource_filename
          self._extract_resource(manager, self._eager_to_zip(name))
        File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1745, in _extract_resource
          self.egg_name, self._parts(zip_path)
        File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1270, in get_cache_path
        File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1250, in extraction_error
          raise err
      pkg_resources.ExtractionError: Can't extract file(s) to egg cache
      The following error occurred while trying to extract file(s) to the Python egg
        [Errno 17] File exists: '/root/.cache/Python-Eggs'
      The Python egg cache directory is currently set to:
      Perhaps your account does not have write access to this directory?  You can
      change the cache directory by setting the PYTHON_EGG_CACHE environment
      variable to point to an accessible directory.

      There is a MWE using Docker at https://github.com/cjmay/thrift-4042 . I reproduced the error on the first run, but you may need to try several runs to reproduce it as it is a race condition.

      This bug only happens when using the new accelerated protocol in thrift 0.10.0 and only happens when thrift has been installed as an egg. When the accelerated protocol is used the fastbinary module is extracted from the installed thrift egg to the Python egg cache. I believe the extraction of the module file itself is atomic (using the rename syscall) but the creation of its parent directory is non-atomic and sometimes results in an error if the fastbinary module is loaded simultaneously by several processes. Note this only occurs the first time the module is loaded, as after that point the parent directory already exists. (This is the justification for using Docker for the MWE.)

      I believe this is the same error as:



      The documentation indicates we can prevent packaging the module into an egg by setting zip_safe to False in setup.py:


      I tried this in the repository linked above and it worked. There are public builds demonstrating it: https://travis-ci.org/cjmay/thrift-4042


        Issue Links



              jking3 James E. King III
              cjmay Chandler May
              0 Vote for this issue
              2 Start watching this issue