diff options
author | Armin Rigo <arigo@tunes.org> | 2015-04-30 09:39:30 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2015-04-30 09:39:30 +0200 |
commit | e36979b86682f41a9d16643a001b4f74880fcdd4 (patch) | |
tree | f0f9ba486e5d3a43319bfda4c4ed46054976e2f9 /cffi/vengine_cpy.py | |
parent | f935a21b2edf14aa2df8379f8256ffcc3f4f0f9e (diff) | |
download | cffi-e36979b86682f41a9d16643a001b4f74880fcdd4.tar.gz |
Acquire the import lock explicitly around the sys.setdlopenflags()
Diffstat (limited to 'cffi/vengine_cpy.py')
-rw-r--r-- | cffi/vengine_cpy.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/cffi/vengine_cpy.py b/cffi/vengine_cpy.py index 1c4668c..9d5bf67 100644 --- a/cffi/vengine_cpy.py +++ b/cffi/vengine_cpy.py @@ -141,19 +141,23 @@ class VCPythonEngine(object): def load_library(self, flags=None): # XXX review all usages of 'self' here! # import it as a new extension module - if hasattr(sys, "getdlopenflags"): - previous_flags = sys.getdlopenflags() + imp.acquire_lock() try: - if hasattr(sys, "setdlopenflags") and flags is not None: - sys.setdlopenflags(flags) - module = imp.load_dynamic(self.verifier.get_module_name(), - self.verifier.modulefilename) - except ImportError as e: - error = "importing %r: %s" % (self.verifier.modulefilename, e) - raise ffiplatform.VerificationError(error) + if hasattr(sys, "getdlopenflags"): + previous_flags = sys.getdlopenflags() + try: + if hasattr(sys, "setdlopenflags") and flags is not None: + sys.setdlopenflags(flags) + module = imp.load_dynamic(self.verifier.get_module_name(), + self.verifier.modulefilename) + except ImportError as e: + error = "importing %r: %s" % (self.verifier.modulefilename, e) + raise ffiplatform.VerificationError(error) + finally: + if hasattr(sys, "setdlopenflags"): + sys.setdlopenflags(previous_flags) finally: - if hasattr(sys, "setdlopenflags"): - sys.setdlopenflags(previous_flags) + imp.release_lock() # # call loading_cpy_struct() to get the struct layout inferred by # the C compiler |