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


Python imp.lock_held方法代码示例

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


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

示例1: test_main

# 需要导入模块: import imp [as 别名]
# 或者: from imp import lock_held [as 别名]
def test_main():        # magic name!  see above
    global N, done

    import imp
    if imp.lock_held():
        # This triggers on, e.g., from test import autotest.
        raise unittest.SkipTest("can't run when import lock is held")

    done.acquire()
    for N in (20, 50) * 3:
        if verbose:
            print "Trying", N, "threads ...",
        for i in range(N):
            thread.start_new_thread(task, ())
        done.acquire()
        if verbose:
            print "OK."
    done.release()

    test_import_hangers() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_threaded_import.py

示例2: test_main

# 需要导入模块: import imp [as 别名]
# 或者: from imp import lock_held [as 别名]
def test_main():        # magic name!  see above
    global N, done

    import imp
    if imp.lock_held():
        # This triggers on, e.g., from test import autotest.
        raise TestSkipped("can't run when import lock is held")

    done.acquire()
    for N in (20, 50) * 3:
        if verbose:
            print "Trying", N, "threads ...",
        for i in range(N):
            thread.start_new_thread(task, ())
        done.acquire()
        if verbose:
            print "OK."
    done.release()

    test_import_hangers() 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:22,代码来源:test_threaded_import.py

示例3: test_main

# 需要导入模块: import imp [as 别名]
# 或者: from imp import lock_held [as 别名]
def test_main():
    if imp.lock_held():
        # If the import lock is held, the threads will hang
        raise unittest.SkipTest("can't run when import lock is held")

    test.test_support.run_unittest(SocketServerTest) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_socketserver.py

示例4: verify_lock_state

# 需要导入模块: import imp [as 别名]
# 或者: from imp import lock_held [as 别名]
def verify_lock_state(self, expected):
        self.assertEqual(imp.lock_held(), expected,
                             "expected imp.lock_held() to be %r" % expected) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_imp.py

示例5: testLock

# 需要导入模块: import imp [as 别名]
# 或者: from imp import lock_held [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

示例6: test_lock

# 需要导入模块: import imp [as 别名]
# 或者: from imp import lock_held [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

示例7: apply

# 需要导入模块: import imp [as 别名]
# 或者: from imp import lock_held [as 别名]
def apply(self, library_name, inputhash, dry_run = False):
        """
        Changes the state of the system according to what the module
        specified does

        Keyword arguments:
            library_name -- the python module to load
            inputhash -- the list of dictionaries of config for the library
            dry_run -- whether or not to actually change the system
        """
        log.debug('entering state.apply %s', [library_name, inputhash, dry_run])
        if library_name not in sys.modules:
            try:
                imp.acquire_lock()
                mod = imp.find_module(library_name, self.libraries)
                imp.load_module(library_name, *mod)
            except ImportError:
                log.exception("Couldn't find module %s in dirs %s", library_name, self.libraries)
                raise
            finally:
                if imp.lock_held():
                    imp.release_lock()
        log.debug('loading library: %s', library_name)
        library = importlib.import_module(library_name)
        schema = library.schema()

        for item in inputhash:
            jsonschema.validate(item, schema)

        failed = library.verify(inputhashes=inputhash, log=log)
        log.debug('dry run: %s', dry_run) 
        if not dry_run:
            log.debug('applying state...')
            library.apply(inputhashes=failed, log=log)
            failed = library.verify(inputhashes=inputhash, log=log)
            if len(failed) > 0:
                log.error("Failed for good on {}".format(failed))
        log.debug('Leaving state.apply %s', failed)
        return failed 
开发者ID:gosquadron,项目名称:squadron,代码行数:41,代码来源:state.py

示例8: post_process

# 需要导入模块: import imp [as 别名]
# 或者: from imp import lock_held [as 别名]
def post_process(self):
        try:
            # set file name
            if self.output == '':
                self.output = self.input[0:-len(self.input.split('.')[-1])-1]+'_out.'+self.input.split('.')[-1]
            # open file for output
            output_file = io.open(self.output, 'w', encoding=self.writeEncoding)
            # write post-processed code to file
            output_file.write(self.__outputBuffer)
        finally:
            output_file.close()

        if self.run:
            # if this module is loaded as a library override the import
            if imp.lock_held() is True:
                self.override_import()
            else:
                self.on_the_fly()
        if not self.save:
            # remove tmp file
            if os.path.exists(self.output):
                os.remove(self.output)
        if not self.resume:
            # break execution so python doesn't
            # run the rest of the pre-processed code
            sys.exit(0)

    # postprocessor - override an import 
开发者ID:interpreters,项目名称:pypreprocessor,代码行数:30,代码来源:__init__.py

示例9: test_main

# 需要导入模块: import imp [as 别名]
# 或者: from imp import lock_held [as 别名]
def test_main():
    import imp
    if imp.lock_held():
        # If the import lock is held, the threads will hang.
        raise TestSkipped("can't run when import lock is held")

    try:
        testall()
    finally:
        cleanup()
    reap_children() 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:13,代码来源:test_socketserver.py


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