Caffe2 - Python API
A deep learning, cross platform ML framework
extension_loader.py
1 ## @package extension_loader
2 # Module caffe2.python.extension_loader
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6 from __future__ import unicode_literals
7 import contextlib
8 import ctypes
9 import sys
10 
11 
12 _set_global_flags = (
13  hasattr(sys, 'getdlopenflags') and hasattr(sys, 'setdlopenflags'))
14 
15 
16 @contextlib.contextmanager
17 def DlopenGuard(extra_flags=ctypes.RTLD_GLOBAL):
18  if _set_global_flags:
19  old_flags = sys.getdlopenflags()
20  sys.setdlopenflags(old_flags | extra_flags)
21  yield
22  if _set_global_flags:
23  sys.setdlopenflags(old_flags)