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


Python _thread.error方法代码示例

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


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

示例1: 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

示例2: test_daemon_threads_fatal_error

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import error [as 别名]
def test_daemon_threads_fatal_error(self):
        subinterp_code = r"""if 1:
            import os
            import threading
            import time

            def f():
                # Make sure the daemon thread is still running when
                # Py_EndInterpreter is called.
                time.sleep(10)
            threading.Thread(target=f, daemon=True).start()
            """
        script = r"""if 1:
            import _testcapi

            _testcapi.run_in_subinterp(%r)
            """ % (subinterp_code,)
        with test.support.SuppressCrashReport():
            rc, out, err = assert_python_failure("-c", script)
        self.assertIn("Fatal Python error: Py_EndInterpreter: "
                      "not the last thread", err.decode()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_threading.py

示例3: abort

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import error [as 别名]
def abort(self):
        """Place the barrier into a 'broken' state.

        Useful in case of error.  Any currently waiting threads and threads
        attempting to 'wait()' will have BrokenBarrierError raised.

        """
        with self._cond:
            self._break() 
开发者ID:war-and-code,项目名称:jawfish,代码行数:11,代码来源:threading.py

示例4: _break

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import error [as 别名]
def _break(self):
        # An internal error was detected.  The barrier is set to
        # a broken state all parties awakened.
        self._state = -2
        self._cond.notify_all() 
开发者ID:war-and-code,项目名称:jawfish,代码行数:7,代码来源:threading.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:
            raise unittest.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:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源: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:
            raise unittest.SkipTest(
                'platform does not support changing thread stack size')
        self.test_various_ops()
        threading.stack_size(0) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_threading.py

示例7: 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 RecursionError:
                    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, stderr=subprocess.PIPE)
        stdout, stderr = p.communicate()
        data = stdout.decode().replace('\r', '')
        self.assertEqual(p.returncode, 0, "Unexpected error: " + stderr.decode())
        self.assertEqual(data, expected_output) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:32,代码来源:test_threading.py

示例8: join

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import error [as 别名]
def join(self, timeout=None):
        """Wait until the thread terminates.

        This blocks the calling thread until the thread whose join() method is
        called terminates -- either normally or through an unhandled exception
        or until the optional timeout occurs.

        When the timeout argument is present and not None, it should be a
        floating point number specifying a timeout for the operation in seconds
        (or fractions thereof). As join() always returns None, you must call
        isAlive() after join() to decide whether a timeout happened -- if the
        thread is still alive, the join() call timed out.

        When the timeout argument is not present or None, the operation will
        block until the thread terminates.

        A thread can be join()ed many times.

        join() raises a RuntimeError if an attempt is made to join the current
        thread as that would cause a deadlock. It is also an error to join() a
        thread before it has been started and attempts to do so raises the same
        exception.

        """
        if not self._initialized:
            raise RuntimeError("Thread.__init__() not called")
        if not self._started.is_set():
            raise RuntimeError("cannot join thread before it is started")
        if self is current_thread():
            raise RuntimeError("cannot join current thread")

        if timeout is None:
            self._wait_for_tstate_lock()
        else:
            # the behavior of a negative timeout isn't documented, but
            # historically .join(timeout=x) for x<0 has acted as if timeout=0
            self._wait_for_tstate_lock(timeout=max(timeout, 0)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:39,代码来源: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, stderr=subprocess.PIPE)
        stdout, stderr = p.communicate()
        data = stdout.decode().replace('\r', '')
        self.assertEqual(p.returncode, 0, "Unexpected error: " + stderr.decode())
        self.assertEqual(data, expected_output) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:32,代码来源:test_threading.py

示例10: __close_transaction

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import error [as 别名]
def __close_transaction(self, table, action):
        "Finishes taking care of a transaction's end."
        table = self.__data.where(name=table)
        assert table.first('type') is not _View, 'Views are not supported!'
        lock = table.first('lock')
        # Begin Critical Section
        with self.__lock:
            try:
                lock.release()
            except _thread.error:
                raise ValueError('Table was not in a transaction!')
            action(table)
        # End Critical Section

    ######################################################################## 
开发者ID:ActiveState,项目名称:code,代码行数:17,代码来源:recipe-577825.py

示例11: release

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import error [as 别名]
def release(self, exc_type=None, exc_value=None, traceback=None):
        "Release lock if locked or possibly throws error."
        try:
            self.__lock.release()
        except _thread.error:
            if self.__verbose:
                raise

    ######################################################################## 
开发者ID:ActiveState,项目名称:code,代码行数:11,代码来源:recipe-577825.py

示例12: __init__

# 需要导入模块: import _thread [as 别名]
# 或者: from _thread import error [as 别名]
def __init__(self, *args, **kwargs):
        "Raises an error since this is an abstract class."
        raise NotImplementedError('This is an abstract class!') 
开发者ID:ActiveState,项目名称:code,代码行数:5,代码来源:recipe-577825.py


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