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


Python imp.acquire_lock方法代码示例

本文整理汇总了Python中imp.acquire_lock方法的典型用法代码示例。如果您正苦于以下问题:Python imp.acquire_lock方法的具体用法?Python imp.acquire_lock怎么用?Python imp.acquire_lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imp的用法示例。


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

示例1: declare_namespace

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def declare_namespace(packageName):
    """Declare that package 'packageName' is a namespace package"""

    _imp.acquire_lock()
    try:
        if packageName in _namespace_packages:
            return

        path, parent = sys.path, None
        if '.' in packageName:
            parent = '.'.join(packageName.split('.')[:-1])
            declare_namespace(parent)
            if parent not in _namespace_packages:
                __import__(parent)
            try:
                path = sys.modules[parent].__path__
            except AttributeError:
                raise TypeError("Not a package:", parent)

        # Track what packages are namespaces, so when new path items are added,
        # they can be updated
        _namespace_packages.setdefault(parent, []).append(packageName)
        _namespace_packages.setdefault(packageName, [])

        for path_item in path:
            # Ensure all the parent's path items are reflected in the child,
            # if they apply
            _handle_ns(packageName, path_item)

    finally:
        _imp.release_lock() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:__init__.py

示例2: fixup_namespace_packages

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def fixup_namespace_packages(path_item, parent=None):
    """Ensure that previously-declared namespace packages include path_item"""
    _imp.acquire_lock()
    try:
        for package in _namespace_packages.get(parent, ()):
            subpath = _handle_ns(package, path_item)
            if subpath:
                fixup_namespace_packages(subpath, package)
    finally:
        _imp.release_lock() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:__init__.py

示例3: declare_namespace

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def declare_namespace(packageName):
    """Declare that package 'packageName' is a namespace package"""

    _imp.acquire_lock()
    try:
        if packageName in _namespace_packages:
            return

        path, parent = sys.path, None
        if '.' in packageName:
            parent = '.'.join(packageName.split('.')[:-1])
            declare_namespace(parent)
            if parent not in _namespace_packages:
                __import__(parent)
            try:
                path = sys.modules[parent].__path__
            except AttributeError:
                raise TypeError("Not a package:", parent)

        # Track what packages are namespaces, so when new path items are added,
        # they can be updated
        _namespace_packages.setdefault(parent,[]).append(packageName)
        _namespace_packages.setdefault(packageName,[])

        for path_item in path:
            # Ensure all the parent's path items are reflected in the child,
            # if they apply
            _handle_ns(packageName, path_item)

    finally:
        _imp.release_lock() 
开发者ID:jpush,项目名称:jbox,代码行数:33,代码来源:__init__.py

示例4: fixup_namespace_packages

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def fixup_namespace_packages(path_item, parent=None):
    """Ensure that previously-declared namespace packages include path_item"""
    _imp.acquire_lock()
    try:
        for package in _namespace_packages.get(parent,()):
            subpath = _handle_ns(package, path_item)
            if subpath:
                fixup_namespace_packages(subpath, package)
    finally:
        _imp.release_lock() 
开发者ID:jpush,项目名称:jbox,代码行数:12,代码来源:__init__.py

示例5: collectPlugins

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def collectPlugins(self):
        """
        This method locates and loads plugins

        Also, it attaches the Panoptes Context, Key/Value Store class and any data to the
        PanoptesPluginInfo object so that these are available to the plugin when it is being executed

        Returns:
            None
        """
        logger = self._panoptes_context.logger
        self.locatePlugins()

        # Set the name of the configuration file so that we can find the mtime for that file while deciding if the
        # the plugin should be executed
        for candidate_infofile, candidate_filepath, plugin_info in self._candidates:
            plugin_info.config_filename = candidate_infofile

        imp.acquire_lock()
        plugins = self.loadPlugins()
        imp.release_lock()
        logger.debug(u'Found %d plugins' % len(plugins))
        for plugin in plugins:
            logger.debug(
                u'Loaded plugin "%s", version "%s" of type "%s", category "%s"' % (
                    plugin.name, plugin.version, self._plugin_type, plugin.category))
            plugin.panoptes_context = self._panoptes_context
            plugin.kv_store_class = self._kv_store_class
            plugin.data = self._data 
开发者ID:yahoo,项目名称:panoptes,代码行数:31,代码来源:manager.py

示例6: unload_modules

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def unload_modules(self):
        logger = self._panoptes_context.logger
        for plugin in self.getAllPlugins():
            plugin_module = plugin.plugin_object.__module__
            logger.debug(u'Deleting module: %s' % plugin_module)
            imp.acquire_lock()
            try:
                del sys.modules[plugin_module]
            except KeyError:
                logger.error('Error trying to delete module "%s" for plugin "%s" with config "%s"' % (
                    plugin_module, plugin.normalized_name, plugin.config))
            finally:
                imp.release_lock()
            del plugin.plugin_object 
开发者ID:yahoo,项目名称:panoptes,代码行数:16,代码来源:manager.py

示例7: declare_namespace

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def declare_namespace(packageName):
    """Declare that package 'packageName' is a namespace package"""

    imp.acquire_lock()
    try:
        if packageName in _namespace_packages:
            return

        path, parent = sys.path, None
        if '.' in packageName:
            parent = '.'.join(packageName.split('.')[:-1])
            declare_namespace(parent)
            if parent not in _namespace_packages:
                __import__(parent)
            try:
                path = sys.modules[parent].__path__
            except AttributeError:
                raise TypeError("Not a package:", parent)

        # Track what packages are namespaces, so when new path items are added,
        # they can be updated
        _namespace_packages.setdefault(parent,[]).append(packageName)
        _namespace_packages.setdefault(packageName,[])

        for path_item in path:
            # Ensure all the parent's path items are reflected in the child,
            # if they apply
            _handle_ns(packageName, path_item)

    finally:
        imp.release_lock() 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:33,代码来源:pkg_resources.py

示例8: fixup_namespace_packages

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def fixup_namespace_packages(path_item, parent=None):
    """Ensure that previously-declared namespace packages include path_item"""
    imp.acquire_lock()
    try:
        for package in _namespace_packages.get(parent,()):
            subpath = _handle_ns(package, path_item)
            if subpath: fixup_namespace_packages(subpath, package)
    finally:
        imp.release_lock() 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:11,代码来源:pkg_resources.py

示例9: declare_namespace

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def declare_namespace(packageName):
    """Declare that package 'packageName' is a namespace package"""

    _imp.acquire_lock()
    try:
        if packageName in _namespace_packages:
            return

        path = sys.path
        parent, _, _ = packageName.rpartition('.')

        if parent:
            declare_namespace(parent)
            if parent not in _namespace_packages:
                __import__(parent)
            try:
                path = sys.modules[parent].__path__
            except AttributeError:
                raise TypeError("Not a package:", parent)

        # Track what packages are namespaces, so when new path items are added,
        # they can be updated
        _namespace_packages.setdefault(parent or None, []).append(packageName)
        _namespace_packages.setdefault(packageName, [])

        for path_item in path:
            # Ensure all the parent's path items are reflected in the child,
            # if they apply
            _handle_ns(packageName, path_item)

    finally:
        _imp.release_lock() 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:34,代码来源:__init__.py

示例10: testLock

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def testLock(self):
        LOOPS = 50

        # The import lock may already be held, e.g. if the test suite is run
        # via "import test.autotest".
        lock_held_at_start = imp.lock_held()
        self.verify_lock_state(lock_held_at_start)

        for i in range(LOOPS):
            imp.acquire_lock()
            self.verify_lock_state(True)

        for i in range(LOOPS):
            imp.release_lock()

        # The original state should be restored now.
        self.verify_lock_state(lock_held_at_start)

        if not lock_held_at_start:
            try:
                imp.release_lock()
            except RuntimeError:
                pass
            else:
                self.fail("release_lock() without lock should raise "
                            "RuntimeError") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:28,代码来源:test_imp.py

示例11: test_import_lock_fork

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def test_import_lock_fork(self):
        import_started = threading.Event()
        fake_module_name = "fake test module"
        partial_module = "partial"
        complete_module = "complete"
        def importer():
            imp.acquire_lock()
            sys.modules[fake_module_name] = partial_module
            import_started.set()
            time.sleep(0.01) # Give the other thread time to try and acquire.
            sys.modules[fake_module_name] = complete_module
            imp.release_lock()
        t = threading.Thread(target=importer)
        t.start()
        import_started.wait()
        pid = os.fork()
        try:
            if not pid:
                m = __import__(fake_module_name)
                if m == complete_module:
                    os._exit(0)
                else:
                    os._exit(1)
            else:
                t.join()
                # Exitcode 1 means the child got a partial module (bad.) No
                # exitcode (but a hang, which manifests as 'got pid 0')
                # means the child deadlocked (also bad.)
                self.wait_impl(pid)
        finally:
            try:
                os.kill(pid, signal.SIGKILL)
            except OSError:
                pass 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:36,代码来源:test_fork1.py

示例12: test_lock

# 需要导入模块: import imp [as 别名]
# 或者: from imp import acquire_lock [as 别名]
def test_lock(self):
        i=0
        while i<5:
            i+=1
            if not imp.lock_held():
                self.assertRaises(RuntimeError,imp.release_lock)
                imp.acquire_lock()
            else:
                imp.release_lock() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_imp.py


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