当前位置: 首页>>代码示例>>Python>>正文


Python sys.getdlopenflags函数代码示例

本文整理汇总了Python中sys.getdlopenflags函数的典型用法代码示例。如果您正苦于以下问题:Python getdlopenflags函数的具体用法?Python getdlopenflags怎么用?Python getdlopenflags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getdlopenflags函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_dlopenflags

 def test_dlopenflags(self):
     self.assertTrue(hasattr(sys, "getdlopenflags"))
     self.assertRaises(TypeError, sys.getdlopenflags, 42)
     oldflags = sys.getdlopenflags()
     self.assertRaises(TypeError, sys.setdlopenflags)
     sys.setdlopenflags(oldflags+1)
     self.assertEqual(sys.getdlopenflags(), oldflags+1)
     sys.setdlopenflags(oldflags)
开发者ID:MaximVanyushkin,项目名称:Sharp.RemoteQueryable,代码行数:8,代码来源:test_sys.py

示例2: test_dlopenflags

 def test_dlopenflags(self):
     import sys
     raises(TypeError, sys.getdlopenflags, 42)
     oldflags = sys.getdlopenflags()
     raises(TypeError, sys.setdlopenflags)
     sys.setdlopenflags(oldflags+1)
     assert sys.getdlopenflags() == oldflags+1
     sys.setdlopenflags(oldflags)
开发者ID:mozillazg,项目名称:pypy,代码行数:8,代码来源:test_sysmodule.py

示例3: __import_extension__

def __import_extension__(name, package, locals):
  """Import a module.

  The 'package' argument is required when performing a relative import. It
  specifies the package to use as the anchor point from which to resolve the
  relative import to an absolute import.

  """

  # This is a fix to the problem of using templates/static/exceptions/dynamic
  # casts with boost.python. It makes all symbols loaded by python from this
  # point onwards global
  default_flags = sys.getdlopenflags()
  sys.setdlopenflags(default_flags|ctypes.RTLD_GLOBAL)

  if name.startswith('.'):
    if not package:
      raise TypeError("relative imports require the 'package' argument")
    level = 0
    for character in name:
      if character != '.':
        break
      level += 1
    name = __resolve_name__(name[level:], package, level)
  __import__(name, locals=locals)
  sys.setdlopenflags(default_flags)

  return sys.modules[name]
开发者ID:azuredsky,项目名称:bob,代码行数:28,代码来源:__init__.py

示例4: setdlopenflags

def setdlopenflags():
    oldflags = sys.getdlopenflags()
    try:
        from DLFCN import RTLD_GLOBAL, RTLD_LAZY
    except ImportError:
        RTLD_GLOBAL = -1
        RTLD_LAZY = -1
        import os

        osname = os.uname()[0]
        if osname == "Linux" or osname == "SunOS" or osname == "FreeBSD":
            RTLD_GLOBAL = 0x100
            RTLD_LAZY = 0x1
        elif osname == "Darwin":
            RTLD_GLOBAL = 0x8
            RTLD_LAZY = 0x1
        del os
    except:
        RTLD_GLOBAL = -1
        RTLD_LAZY = -1

    if RTLD_GLOBAL != -1 and RTLD_LAZY != -1:
        sys.setdlopenflags(RTLD_LAZY | RTLD_GLOBAL)

    return oldflags
开发者ID:rggjan,项目名称:gegl-global-matting,代码行数:25,代码来源:__init__.py

示例5: DlopenGuard

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)
开发者ID:Ralfhund,项目名称:caffe2,代码行数:7,代码来源:extension_loader.py

示例6: imp_load_module

 def imp_load_module(name, *args):
     pathParts = args[1].split(os.path.sep)
     extension = os.path.splitext(pathParts[-1])[-1]
     # Find all swigged LSST libs.  Load _lsstcppimport.so by
     # adding it to the EXCEPTIONLIST since it may not have lsst in
     # the path (it's in $BASE_DIR/python, not
     # $BASE_DIR/python/lsst).  Also, look for paths that look like
     # python/lsst as that is how to know if you are in an LSST
     # package.
     lsstIdx = [i for i, el in enumerate(pathParts) if el == 'python']
     if pathParts[-1] in LIB_EXCEPTION_LIST or (extension in SHARED_LIB_EXTENSION_LIST and
                                                pathParts[-1].startswith('_') and
                                                'lsst' in [pathParts[i + 1] for i in lsstIdx]):
         # Get currently set flags
         originalDLFlags = sys.getdlopenflags()
         # Set flags
         sys.setdlopenflags(DLFLAGS)
         try:
             module = orig_imp_load_module(name, *args)
         finally:
             # Set original flags
             sys.setdlopenflags(originalDLFlags)
     else:
         module = orig_imp_load_module(name, *args)
     return module
开发者ID:HyperSuprime-Cam,项目名称:base,代码行数:25,代码来源:lsstimport.py

示例7: _load_libzmq

def _load_libzmq():
    """load bundled libzmq if there is one"""
    import sys, ctypes, platform, os
    dlopen = hasattr(sys, 'getdlopenflags') # unix-only
    # RTLD flags are added to os in Python 3
    # get values from os because ctypes values are WRONG on pypy
    PYPY = platform.python_implementation().lower() == 'pypy'
    
    if dlopen:
        dlflags = sys.getdlopenflags()
        # set RTLD_GLOBAL, unset RTLD_LOCAL
        flags = ctypes.RTLD_GLOBAL | dlflags
        # ctypes.RTLD_LOCAL is 0 on pypy, which is *wrong*
        flags &= ~ getattr(os, 'RTLD_LOCAL', 4)
        # pypy on darwin needs RTLD_LAZY for some reason
        if PYPY and sys.platform == 'darwin':
            flags |= getattr(os, 'RTLD_LAZY', 1)
            flags &= ~ getattr(os, 'RTLD_NOW', 2)
        sys.setdlopenflags(flags)
    try:
        from . import libzmq
    except ImportError:
        pass
    else:
        # store libzmq as zmq._libzmq for backward-compat
        globals()['_libzmq'] = libzmq
        if PYPY:
            # some versions of pypy (5.3 < ? < 5.8) needs explicit CDLL load for some reason,
            # otherwise symbols won't be globally available
            # do this unconditionally because it should be harmless (?)
            ctypes.CDLL(libzmq.__file__, ctypes.RTLD_GLOBAL)
    finally:
        if dlopen:
            sys.setdlopenflags(dlflags)
开发者ID:dennislwm,项目名称:pyzmq,代码行数:34,代码来源:__init__.py

示例8: modified_dlopenflags

def modified_dlopenflags(dlopenflags):
    try:
        old_dlopenflags = sys.getdlopenflags()
        sys.setdlopenflags(dlopenflags)
        yield
    finally:
        sys.setdlopenflags(old_dlopenflags)
开发者ID:tbarnetlamb,项目名称:hyphen,代码行数:7,代码来源:__init__.py

示例9: enableHouModule

def enableHouModule():
    """Set up the environment so that "import hou" works."""

    # Handle dlopen flags so dsos can be loaded correctly.
    if hasattr(sys, "setdlopenflags"):
        import DLFCN

        old_dlopen_flags = sys.getdlopenflags()
        sys.setdlopenflags(old_dlopen_flags | DLFCN.RTLD_GLOBAL)

    # Try to import hou.
    try:
        import hou
    # If it can't find it, make sure it is in the path.
    except ImportError:
        # Python needs to know where the hou module is.
        path = os.path.join(
            os.getenv("HH"),
            "python{}.{}".format(sys.version_info[0], sys.version_info[1])
        )

        # Append the path.
        sys.path.append(path)

        # Try again.
        import hou

    finally:
        # Restore old flags.
        if hasattr(sys, "setdlopenflags"):
            sys.setdlopenflags(old_dlopen_flags)
开发者ID:follyx,项目名称:Houdini-Toolbox,代码行数:31,代码来源:test_inline.py

示例10: DlopenGuard

def DlopenGuard():
    # In python 2.7 required constants are not defined.
    # Thus they are listed explicitly
    flags = sys.getdlopenflags()
    sys.setdlopenflags(DLFCN.RTLD_GLOBAL | DLFCN.RTLD_NOW)
    yield
    sys.setdlopenflags(flags)
开发者ID:maniacs-satm,项目名称:caffe2,代码行数:7,代码来源:extension_loader.py

示例11: setDLFlags

def setDLFlags():
    # brought over from ITK Wrapping/CSwig/Python

    # Python "help(sys.setdlopenflags)" states:
    #
    # setdlopenflags(...)
    #     setdlopenflags(n) -> None
    #     
    #     Set the flags that will be used for dlopen() calls. Among other
    #     things, this will enable a lazy resolving of symbols when
    #     importing a module, if called as sys.setdlopenflags(0) To share
    #     symbols across extension modules, call as
    #
    #     sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)
    #
    # GCC 3.x depends on proper merging of symbols for RTTI:
    #   http://gcc.gnu.org/faq.html#dso
    #
    try:
        import dl
        newflags = dl.RTLD_NOW|dl.RTLD_GLOBAL
    except:
        newflags = 0x102  # No dl module, so guess (see above).
        
    try:
        oldflags = sys.getdlopenflags()
        sys.setdlopenflags(newflags)
    except:
        oldflags = None

    return oldflags
开发者ID:fvpolpeta,项目名称:devide,代码行数:31,代码来源:__init__.py

示例12: loadGenius

def loadGenius():
    if sys.platform=='win32':
        modulePath = '/lib/genius.pyd'
    else:
        modulePath = '/lib/genius.so'

    searchPath = [ os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + '/..'),
                  '.', '..']
    if os.environ.has_key('GENIUS_DIR'):
        searchPath.insert(0, os.environ['GENIUS_DIR'])
        
    GeniusDir = None
    for path in searchPath:
        if os.path.exists(path+modulePath):
            GeniusDir = os.path.abspath(path)
            break
    
    if GeniusDir==None:
        raise GeniusError('Genius library binaries are not found.')
            
    sys.path.insert(0, GeniusDir+'/lib')
    
    global genius
    try:
        flagsave = sys.getdlopenflags()
        if sys.platform=='linux2':
            import DLFCN
            sys.setdlopenflags(DLFCN.RTLD_NOW|DLFCN.RTLD_GLOBAL)
        import genius
        sys.setdlopenflags(flagsave)
    except ImportError:
        raise GeniusError('Failed loading Genius binaries.')

    genius.Genius.set_genius_dir(GeniusDir)
    genius.baseDir = GeniusDir
开发者ID:Shallouf,项目名称:Genius-TCAD-Open,代码行数:35,代码来源:test.py

示例13: enableHouModule

def enableHouModule():
    '''Set up the environment so that "import hou" works.'''
    #import sys, os

    # Importing hou will load in Houdini's libraries and initialize Houdini.
    # In turn, Houdini will load any HDK extensions written in C++.  These
    # extensions need to link against Houdini's libraries, so we need to
    # make sure that the symbols from Houdini's libraries are visible to
    # other libraries that Houdini loads.  So, we adjust Python's dlopen
    # flags before importing hou.
    HFS = "/opt/hfs.current"
    if hasattr(sys, "setdlopenflags"):
        old_dlopen_flags = sys.getdlopenflags()
        import DLFCN
        sys.setdlopenflags(old_dlopen_flags | DLFCN.RTLD_GLOBAL)

    try:
        import hou
    except ImportError:
        # Add $HFS/houdini/python2.6libs to sys.path so Python can find the
        # hou module.
        sys.path.append(HFS + "/houdini/python%d.%dlibs" % sys.version_info[:2])
        #sys.path.append(os.environ['HFS'] + "/houdini/python2.6libs")
        import hou
    finally:
        if hasattr(sys, "setdlopenflags"):
            sys.setdlopenflags(old_dlopen_flags)
开发者ID:Azmisov,项目名称:ramshorn-tools,代码行数:27,代码来源:installHoudiniFile.py

示例14: load_prepare

def load_prepare(mod_path, depends_on, has_dependent):
        root_name = mod_path[0]
        mod_name = os.path.basename(root_name)

        env_var_name = 'LIMA_%s_VERSION' % mod_name.upper()
        if env_var_name in os.environ:
                version = os.environ[env_var_name]
        else:
                version = 'LAST'

        if version.upper() == 'LAST':
                version_filter = []
        elif version_re.match(version):
                version_filter = version_code(version)
        else:
                raise ImportError('Invalid %s: %s' % (env_var_name, version))

        def good_dir(v, r=root_name, f=version_filter):
                return good_version_dir(v, r, f)

        version_dirs = [x for x in os.listdir(root_name) if good_dir(x)]
        if not version_dirs:
                raise ImportError('Invalid %s: %s' % (env_var_name, version))

        version_dirs.sort(key=version_code)
        version = version_dirs[-1]
        mod_dir = os.path.join(root_name, version)
        ld_open_flags = sys.getdlopenflags()

        cleanup_data = mod_path, mod_dir, ld_open_flags, has_dependent

        if not depends_on:
                return load_ld_prepare(cleanup_data)

        cap_dep = depends_on.upper()
        dep_version_fname = os.path.join(mod_dir, '%s_VERSION' % cap_dep)
        dep_version_file = open(dep_version_fname, 'rt')
        dep_version = dep_version_file.readline().strip()

        link_strict_version = os.environ['LIMA_LINK_STRICT_VERSION']
        if link_strict_version == 'MINOR':
                dep_version = VSEP.join(dep_version.split(VSEP)[:2])
        elif link_strict_version != 'FULL':
                raise ImportError('Invalid LIMA_LINK_STRICT_VERSION var: %s' %
                                  link_strict_version)
        
        env_var_name = 'LIMA_%s_VERSION' % cap_dep
        if env_var_name in os.environ:
                prev_version = os.environ[env_var_name]
                if prev_version != dep_version:
                        msg = 'Forcing %s to %s, which was previously set to '\
                              '%s' % (env_var_name, dep_version, prev_version)
                        raise ImportError('%s: %s' % (mod_name, msg))
        else:
                os.environ[env_var_name] = dep_version

        return cleanup_data
开发者ID:Erlaak,项目名称:Lima,代码行数:57,代码来源:module_helper.py

示例15: load_library

 def load_library(self, flags=None):
     # XXX review all usages of 'self' here!
     # import it as a new extension module
     imp.acquire_lock()
     try:
         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:
         imp.release_lock()
     #
     # call loading_cpy_struct() to get the struct layout inferred by
     # the C compiler
     self._load(module, 'loading')
     #
     # the C code will need the <ctype> objects.  Collect them in
     # order in a list.
     revmapping = dict([(value, key)
                        for (key, value) in self._typesdict.items()])
     lst = [revmapping[i] for i in range(len(revmapping))]
     lst = list(map(self.ffi._get_cached_btype, lst))
     #
     # build the FFILibrary class and instance and call _cffi_setup().
     # this will set up some fields like '_cffi_types', and only then
     # it will invoke the chained list of functions that will really
     # build (notably) the constant objects, as <cdata> if they are
     # pointers, and store them as attributes on the 'library' object.
     class FFILibrary(object):
         _cffi_python_module = module
         _cffi_ffi = self.ffi
         _cffi_dir = []
         def __dir__(self):
             return FFILibrary._cffi_dir + list(self.__dict__)
     library = FFILibrary()
     if module._cffi_setup(lst, ffiplatform.VerificationError, library):
         import warnings
         warnings.warn("reimporting %r might overwrite older definitions"
                       % (self.verifier.get_module_name()))
     #
     # finally, call the loaded_cpy_xxx() functions.  This will perform
     # the final adjustments, like copying the Python->C wrapper
     # functions from the module to the 'library' object, and setting
     # up the FFILibrary class with properties for the global C variables.
     self._load(module, 'loaded', library=library)
     module._cffi_original_ffi = self.ffi
     module._cffi_types_of_builtin_funcs = self._types_of_builtin_functions
     return library
开发者ID:06094051,项目名称:XX-Net,代码行数:57,代码来源:vengine_cpy.py


注:本文中的sys.getdlopenflags函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。