Ticket #6234: trac-6234-pt2.patch

File trac-6234-pt2.patch, 1.9 KB (added by craigcitro, 12 years ago)
  • setup.py

    # HG changeset patch
    # User Craig Citro <craigcitro@gmail.com>
    # Date 1244772720 25200
    # Node ID b8fff2295d432e9fa9ab70f77bcb31db8709b8e5
    # Parent  43a8b91f5a50422494f8c521cae7d2b256f811f7
    Additional fix for race condition with parallel distutils, see trac #6234.
    
    diff -r 43a8b91f5a50 -r b8fff2295d43 setup.py
    a b  
    326326            package_dir = build_py.get_package_dir(package)
    327327            ext_filename = os.path.join(package_dir,
    328328                                        self.get_ext_filename(base))
     329            relative_ext_filename = self.get_ext_filename(base)
    329330        else:
    330331            ext_filename = os.path.join(self.build_lib,
    331332                                        self.get_ext_filename(fullname))
     333            relative_ext_filename = self.get_ext_filename(fullname)
     334
     335        # while dispatching the calls to gcc in parallel, we sometimes
     336        # hit a race condition where two separate build_ext objects
     337        # try to create a given directory at the same time; whoever
     338        # loses the race then seems to throw an error, saying that
     339        # the directory already exists. so, instead of fighting to
     340        # fix the race condition, we simply make sure the entire
     341        # directory tree exists now, while we're processing the
     342        # extensions in serial.
     343        relative_ext_dir = os.path.split(relative_ext_filename)[0]
     344        prefixes = ['', self.build_lib, self.build_temp]
     345        for prefix in prefixes:
     346            path = os.path.join(prefix, relative_ext_dir)
     347            if not os.path.exists(path):
     348                os.makedirs(path)
     349                           
    332350        depends = sources + ext.depends
    333351        if not (self.force or newer_group(depends, ext_filename, 'newer')):
    334352            log.debug("skipping '%s' extension (up-to-date)", ext.name)