當前位置: 首頁>>代碼示例>>Python>>正文


Python concurrent.run_on_executor方法代碼示例

本文整理匯總了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) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:15,代碼來源:concurrent_test.py

示例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) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:15,代碼來源:concurrent_test.py

示例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) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:15,代碼來源:concurrent_test.py

示例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) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:15,代碼來源:concurrent_test.py

示例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) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:15,代碼來源:concurrent_test.py

示例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 
開發者ID:dalibo,項目名稱:temboard,代碼行數:5,代碼來源:web.py

示例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'] 
開發者ID:dalibo,項目名稱:temboard,代碼行數:12,代碼來源:web.py

示例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 
開發者ID:dalibo,項目名稱:temboard,代碼行數:53,代碼來源:web.py


注:本文中的tornado.concurrent.run_on_executor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。