2017-03-29 13:44:02 +00:00
|
|
|
## @package extension_loader
|
|
|
|
|
# Module caffe2.python.extension_loader
|
2016-07-21 18:26:41 +00:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
from __future__ import division
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
import contextlib
|
2017-03-30 21:27:35 +00:00
|
|
|
import ctypes
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_set_global_flags = (
|
|
|
|
|
hasattr(sys, 'getdlopenflags') and hasattr(sys, 'setdlopenflags'))
|
|
|
|
|
|
2016-07-21 18:26:41 +00:00
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
|
def DlopenGuard():
|
2017-03-30 21:27:35 +00:00
|
|
|
if _set_global_flags:
|
|
|
|
|
old_flags = sys.getdlopenflags()
|
|
|
|
|
sys.setdlopenflags(old_flags | ctypes.RTLD_GLOBAL)
|
2016-07-21 18:26:41 +00:00
|
|
|
yield
|
2017-03-30 21:27:35 +00:00
|
|
|
if _set_global_flags:
|
|
|
|
|
sys.setdlopenflags(old_flags)
|