本文整理汇总了Python中gevent.threadpool.ThreadPool.size方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.size方法的具体用法?Python ThreadPool.size怎么用?Python ThreadPool.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gevent.threadpool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_auto_timeout_client__short_timeout_on_stuck_server
# 需要导入模块: from gevent.threadpool import ThreadPool [as 别名]
# 或者: from gevent.threadpool.ThreadPool import size [as 别名]
def test_auto_timeout_client__short_timeout_on_stuck_server(self):
import time
from threading import Event
wait_for_start = Event()
wait_for_close = Event()
def thread_server(wait_for_start, wait_for_close):
try:
print(("starting server, hub: {}".format(gevent.hub.get_hub())))
with logbook.NullHandler().applicationbound():
with server_context(FooService(), max_response_time=0.1):
print("server started.")
wait_for_start.set()
while not wait_for_close.is_set():
gevent.sleep(0.1)
except:
import traceback
traceback.print_exc()
from gevent.threadpool import ThreadPool
t = ThreadPool(1)
t.size = 1
t.spawn(thread_server, wait_for_start, wait_for_close)
try:
print(("starting client, hub: {}".format(gevent.hub.get_hub())))
client = AutoTimeoutClient(ZeroRPCClientTransport.create_tcp(8192), timeout_calc_func=lambda n: n * 2)
wait_for_start.wait()
print("client started.")
t1 = time.time()
self.assertRaises(TimeoutExpired, client.stuck_call)
t2 = time.time()
# This test should always pass although we're dealing with timing and non-deterministic measures since
# stuck_call() is stuck for an entire second while we're comparing time to 0.2 (almost an order of a
# magnitude)
self.assertAlmostEqual(0.2, t2 - t1, delta=0.2)
finally:
wait_for_close.set()
t.join()
示例2: _ppool
# 需要导入模块: from gevent.threadpool import ThreadPool [as 别名]
# 或者: from gevent.threadpool.ThreadPool import size [as 别名]
def _ppool():
pool = ThreadPool(PAR_COUNT)
pool.size = PAR_COUNT
return pool