summaryrefslogtreecommitdiff
path: root/cffi/vengine_cpy.py
diff options
context:
space:
mode:
Diffstat (limited to 'cffi/vengine_cpy.py')
-rw-r--r--cffi/vengine_cpy.py26
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