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


Python thread.error方法代码示例

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


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

示例1: _run_and_join

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def _run_and_join(self, script):
        script = """if 1:
            import sys, os, time, threading

            # a thread, which waits for the main program to terminate
            def joiningfunc(mainthread):
                mainthread.join()
                print 'end of thread'
        \n""" + script

        p = subprocess.Popen([sys.executable, "-c", script], stdout=subprocess.PIPE)
        rc = p.wait()
        data = p.stdout.read().replace('\r', '')
        p.stdout.close()
        self.assertEqual(data, "end of main\nend of thread\n")
        self.assertFalse(rc == 2, "interpreter was blocked")
        self.assertTrue(rc == 0, "Unexpected error") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_threading.py

示例2: acquire

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def acquire(self, blocking=True, timeout=-1):
            # Transform the default -1 argument into the None that our
            # semaphore implementation expects, and raise the same error
            # the stdlib implementation does.
            if timeout == -1:
                timeout = None
            if not blocking and timeout is not None:
                raise ValueError("can't specify a timeout for a non-blocking call")
            if timeout is not None:
                if timeout < 0:
                    # in C: if(timeout < 0 && timeout != -1)
                    raise ValueError("timeout value must be strictly positive")
                if timeout > self._TIMEOUT_MAX:
                    raise OverflowError('timeout value is too large')

            return BoundedSemaphore.acquire(self, blocking, timeout) 
开发者ID:leancloud,项目名称:satori,代码行数:18,代码来源:thread.py

示例3: test_various_ops_large_stack

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def test_various_ops_large_stack(self):
        if verbose:
            print 'with 1MB thread stack size...'
        try:
            threading.stack_size(0x100000)
        except thread.error:
            if verbose:
                print 'platform does not support changing thread stack size'
            return
        self.test_various_ops()
        threading.stack_size(0)

    # this test is not applicable to jython since
    # 1. Lock is equiv to RLock, so this weird sync behavior won't be seen
    # 2. We use a weak hash map to map these threads
    # 3. This behavior doesn't make sense for Jython since any foreign
    #    Java threads can use the same underlying locks, etc 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:19,代码来源:test_threading.py

示例4: runThreads

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def runThreads(numThreads, threadFunction, forwardException=True, startThreadMsg=True):
    threads = []

    kb.multiThreadMode = True
    kb.threadContinue = True
    kb.threadException = False

    try:
        if numThreads > 1:
            if startThreadMsg:
                infoMsg = "starting %d threads" % numThreads
                logger.log(CUSTOM_LOGGING.SYSINFO, infoMsg)

        else:
            threadFunction()
            return

        for numThread in xrange(numThreads):
            thread = threading.Thread(target=exceptionHandledFunction, name=str(numThread), args=[threadFunction])

            setDaemon(thread)

            try:
                thread.start()
            except threadError, errMsg:
                errMsg = "error occurred while starting new thread ('%s')" % errMsg
                logger.log(CUSTOM_LOGGING.ERROR, errMsg)
                break

            threads.append(thread)

        # And wait for them to all finish
        alive = True
        while alive:
            alive = False
            for thread in threads:
                if thread.isAlive():
                    alive = True
                    time.sleep(0.1) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:41,代码来源:threads.py

示例5: test_various_ops_small_stack

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def test_various_ops_small_stack(self):
        if verbose:
            print 'with 256kB thread stack size...'
        try:
            threading.stack_size(262144)
        except thread.error:
            self.skipTest('platform does not support changing thread stack size')
        self.test_various_ops()
        threading.stack_size(0)

    # run with a large thread stack size (1MB) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_threading.py

示例6: test_various_ops_large_stack

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def test_various_ops_large_stack(self):
        if verbose:
            print 'with 1MB thread stack size...'
        try:
            threading.stack_size(0x100000)
        except thread.error:
            self.skipTest('platform does not support changing thread stack size')
        self.test_various_ops()
        threading.stack_size(0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_threading.py

示例7: test_limbo_cleanup

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def test_limbo_cleanup(self):
        # Issue 7481: Failure to start thread should cleanup the limbo map.
        def fail_new_thread(*args):
            raise thread.error()
        _start_new_thread = threading._start_new_thread
        threading._start_new_thread = fail_new_thread
        try:
            t = threading.Thread(target=lambda: None)
            self.assertRaises(thread.error, t.start)
            self.assertFalse(
                t in threading._limbo,
                "Failed to cleanup _limbo map on failure of Thread.start().")
        finally:
            threading._start_new_thread = _start_new_thread 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_threading.py

示例8: test_finalize_with_trace

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def test_finalize_with_trace(self):
        # Issue1733757
        # Avoid a deadlock when sys.settrace steps into threading._shutdown
        p = subprocess.Popen([sys.executable, "-c", """if 1:
            import sys, threading

            # A deadlock-killer, to prevent the
            # testsuite to hang forever
            def killer():
                import os, time
                time.sleep(2)
                print 'program blocked; aborting'
                os._exit(2)
            t = threading.Thread(target=killer)
            t.daemon = True
            t.start()

            # This is the trace function
            def func(frame, event, arg):
                threading.current_thread()
                return func

            sys.settrace(func)
            """],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        self.addCleanup(p.stdout.close)
        self.addCleanup(p.stderr.close)
        stdout, stderr = p.communicate()
        rc = p.returncode
        self.assertFalse(rc == 2, "interpreted was blocked")
        self.assertTrue(rc == 0,
                        "Unexpected error: " + repr(stderr)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:35,代码来源:test_threading.py

示例9: test_recursion_limit

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def test_recursion_limit(self):
        # Issue 9670
        # test that excessive recursion within a non-main thread causes
        # an exception rather than crashing the interpreter on platforms
        # like Mac OS X or FreeBSD which have small default stack sizes
        # for threads
        script = """if True:
            import threading

            def recurse():
                return recurse()

            def outer():
                try:
                    recurse()
                except RuntimeError:
                    pass

            w = threading.Thread(target=outer)
            w.start()
            w.join()
            print('end of main thread')
            """
        expected_output = "end of main thread\n"
        p = subprocess.Popen([sys.executable, "-c", script],
                             stdout=subprocess.PIPE)
        stdout, stderr = p.communicate()
        data = stdout.decode().replace('\r', '')
        self.assertEqual(p.returncode, 0, "Unexpected error")
        self.assertEqual(data, expected_output) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:32,代码来源:test_threading.py

示例10: test_various_ops_small_stack

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def test_various_ops_small_stack(self):
        if verbose:
            print 'with 256kB thread stack size...'
        try:
            threading.stack_size(262144)
        except thread.error:
            if verbose:
                print 'platform does not support changing thread stack size'
            return
        self.test_various_ops()
        threading.stack_size(0)

    # run with a large thread stack size (1MB) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:15,代码来源:test_threading.py

示例11: test_various_ops_large_stack

# 需要导入模块: import thread [as 别名]
# 或者: from thread import error [as 别名]
def test_various_ops_large_stack(self):
        if verbose:
            print 'with 1MB thread stack size...'
        try:
            threading.stack_size(0x100000)
        except thread.error:
            if verbose:
                print 'platform does not support changing thread stack size'
            return
        self.test_various_ops()
        threading.stack_size(0) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:13,代码来源:test_threading.py


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