本文整理汇总了Python中tornado.concurrent.run_on_executor方法的典型用法代码示例。如果您正苦于以下问题:Python concurrent.run_on_executor方法的具体用法?Python concurrent.run_on_executor怎么用?Python concurrent.run_on_executor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.concurrent
的用法示例。
在下文中一共展示了concurrent.run_on_executor方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_calling
# 需要导入模块: from tornado import concurrent [as 别名]
# 或者: from tornado.concurrent import run_on_executor [as 别名]
def test_no_calling(self):
class Object(object):
def __init__(self, io_loop):
self.io_loop = io_loop
self.executor = futures.thread.ThreadPoolExecutor(1)
@run_on_executor
def f(self):
return 42
o = Object(io_loop=self.io_loop)
answer = yield o.f()
self.assertEqual(answer, 42)
示例2: test_call_with_no_args
# 需要导入模块: from tornado import concurrent [as 别名]
# 或者: from tornado.concurrent import run_on_executor [as 别名]
def test_call_with_no_args(self):
class Object(object):
def __init__(self, io_loop):
self.io_loop = io_loop
self.executor = futures.thread.ThreadPoolExecutor(1)
@run_on_executor()
def f(self):
return 42
o = Object(io_loop=self.io_loop)
answer = yield o.f()
self.assertEqual(answer, 42)
示例3: test_call_with_io_loop
# 需要导入模块: from tornado import concurrent [as 别名]
# 或者: from tornado.concurrent import run_on_executor [as 别名]
def test_call_with_io_loop(self):
class Object(object):
def __init__(self, io_loop):
self._io_loop = io_loop
self.executor = futures.thread.ThreadPoolExecutor(1)
@run_on_executor(io_loop='_io_loop')
def f(self):
return 42
o = Object(io_loop=self.io_loop)
answer = yield o.f()
self.assertEqual(answer, 42)
示例4: test_call_with_executor
# 需要导入模块: from tornado import concurrent [as 别名]
# 或者: from tornado.concurrent import run_on_executor [as 别名]
def test_call_with_executor(self):
class Object(object):
def __init__(self, io_loop):
self.io_loop = io_loop
self.__executor = futures.thread.ThreadPoolExecutor(1)
@run_on_executor(executor='_Object__executor')
def f(self):
return 42
o = Object(io_loop=self.io_loop)
answer = yield o.f()
self.assertEqual(answer, 42)
示例5: test_call_with_both
# 需要导入模块: from tornado import concurrent [as 别名]
# 或者: from tornado.concurrent import run_on_executor [as 别名]
def test_call_with_both(self):
class Object(object):
def __init__(self, io_loop):
self._io_loop = io_loop
self.__executor = futures.thread.ThreadPoolExecutor(1)
@run_on_executor(io_loop='_io_loop', executor='_Object__executor')
def f(self):
return 42
o = Object(io_loop=self.io_loop)
answer = yield o.f()
self.assertEqual(answer, 42)
示例6: executor
# 需要导入模块: from tornado import concurrent [as 别名]
# 或者: from tornado.concurrent import run_on_executor [as 别名]
def executor(self):
# To enable @run_on_executor methods, we must have executor property.
return self.application.executor
示例7: initialize
# 需要导入模块: from tornado import concurrent [as 别名]
# 或者: from tornado.concurrent import run_on_executor [as 别名]
def initialize(self, callable_, blueprint=None, methods=None, logger=None):
self.callable_ = callable_
self.logger = logger or logging.getLogger(__name__)
self.request.blueprint = blueprint
self.request.config = self.application.config
# run_on_executor searches for `executor` attribute of first argument.
# Thus, we bind executor to request object.
self.request.executor = self.executor
self.request.handler = self
self.SUPPORTED_METHODS = methods or ['GET']
示例8: route
# 需要导入模块: from tornado import concurrent [as 别名]
# 或者: from tornado.concurrent import run_on_executor [as 别名]
def route(self, url, methods=None, with_instance=False, json=None):
# Implements flask-like route registration of a simple synchronous
# callable.
# Enable JSON middleware on /json/ handlers.
if json is None:
json = url.startswith('/json/')
def decorator(func):
logger_name = func.__module__ + '.' + func.__name__
func = UserHelper.add_middleware(func)
if with_instance:
func = InstanceHelper.add_middleware(func)
if url.startswith('/server/') or url.startswith('/proxy/'):
# Limit user/instance access control to /server/ and
# /proxy/.
# Admin area access control has already been performed
func = add_user_instance_middleware(func)
if json:
func = add_json_middleware(func)
func = ErrorHelper.add_middleware(func)
func = DatabaseHelper.add_middleware(func)
@run_on_executor
@functools.wraps(func)
def sync_request_wrapper(request, *args):
try:
return func(request, *args)
except (Redirect, HTTPError):
raise
except Exception as e:
# Since async traceback is useless, spit here traceback and
# forge simple HTTPError(500), no HTML error.
logger.exception("Unhandled Error:")
raise HTTPError(500, str(e))
rules = [(
url, CallableHandler, dict(
blueprint=self,
callable_=sync_request_wrapper,
methods=methods or ['GET'],
logger=logging.getLogger(logger_name),
),
)]
self.add_rules(rules)
return func
return decorator