本文整理匯總了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)
示例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())
示例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()
示例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()
示例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)
示例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)
示例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)
示例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))
示例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)
示例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
########################################################################
示例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
########################################################################
示例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!')