mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Summary: There is a module called `2to3` which you can target for future specifically to remove these, the directory of `caffe2` has the most redundant imports: ```2to3 -f future -w caffe2``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/45033 Reviewed By: seemethere Differential Revision: D23808648 Pulled By: bugra fbshipit-source-id: 38971900f0fe43ab44a9168e57f2307580d36a38
30 lines
744 B
Python
30 lines
744 B
Python
## @package extension_loader
|
|
# Module caffe2.python.extension_loader
|
|
|
|
|
|
|
|
|
|
import contextlib
|
|
import ctypes
|
|
import sys
|
|
|
|
|
|
_set_global_flags = (
|
|
hasattr(sys, 'getdlopenflags') and hasattr(sys, 'setdlopenflags'))
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def DlopenGuard(extra_flags=ctypes.RTLD_GLOBAL):
|
|
if _set_global_flags:
|
|
old_flags = sys.getdlopenflags()
|
|
sys.setdlopenflags(old_flags | extra_flags)
|
|
|
|
# in case we dlopen something that doesn't exist, yield will fail and throw;
|
|
# we need to remember reset the old flags to clean up, otherwise RTLD_GLOBAL
|
|
# flag will stick around and create symbol conflict problems
|
|
try:
|
|
yield
|
|
finally:
|
|
if _set_global_flags:
|
|
sys.setdlopenflags(old_flags)
|