pytorch/caffe2/python/extension_loader.py
Yangqing Jia ffd1883229 Make extension loader properly handle visibility.
Summary:
(Also, exposed the macros that we use during build time via the macros.h header file)
Closes https://github.com/caffe2/caffe2/pull/233

Differential Revision: D4803311

Pulled By: Yangqing

fbshipit-source-id: 9f8ce57692f81f7a8994344846d3c90aa2c7070a
2017-03-30 14:38:38 -07:00

24 lines
604 B
Python

## @package extension_loader
# Module caffe2.python.extension_loader
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import contextlib
import ctypes
import sys
_set_global_flags = (
hasattr(sys, 'getdlopenflags') and hasattr(sys, 'setdlopenflags'))
@contextlib.contextmanager
def DlopenGuard():
if _set_global_flags:
old_flags = sys.getdlopenflags()
sys.setdlopenflags(old_flags | ctypes.RTLD_GLOBAL)
yield
if _set_global_flags:
sys.setdlopenflags(old_flags)