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


Python asyncio.isfuture方法代碼示例

本文整理匯總了Python中asyncio.isfuture方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.isfuture方法的具體用法?Python asyncio.isfuture怎麽用?Python asyncio.isfuture使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在asyncio的用法示例。


在下文中一共展示了asyncio.isfuture方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_isfuture

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def test_isfuture(self):
        class MyFuture:
            _asyncio_future_blocking = None

            def __init__(self):
                self._asyncio_future_blocking = False

        self.assertFalse(asyncio.isfuture(MyFuture))
        self.assertTrue(asyncio.isfuture(MyFuture()))

        self.assertFalse(asyncio.isfuture(1))
        self.assertFalse(asyncio.isfuture(asyncio.Future))

        # As `isinstance(Mock(), Future)` returns `False`
        self.assertFalse(asyncio.isfuture(mock.Mock()))

        # As `isinstance(Mock(Future), Future)` returns `True`
        self.assertTrue(asyncio.isfuture(mock.Mock(asyncio.Future)))

        f = asyncio.Future(loop=self.loop)
        self.assertTrue(asyncio.isfuture(f))
        f.cancel() 
開發者ID:ShikyoKira,項目名稱:Project-New-Reign---Nemesis-Main,代碼行數:24,代碼來源:test_futures.py

示例2: test_isfuture

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def test_isfuture(self):
        class MyFuture:
            _asyncio_future_blocking = None

            def __init__(self):
                self._asyncio_future_blocking = False

        self.assertFalse(asyncio.isfuture(MyFuture))
        self.assertTrue(asyncio.isfuture(MyFuture()))
        self.assertFalse(asyncio.isfuture(1))

        # As `isinstance(Mock(), Future)` returns `False`
        self.assertFalse(asyncio.isfuture(mock.Mock()))

        f = self._new_future(loop=self.loop)
        self.assertTrue(asyncio.isfuture(f))
        self.assertFalse(asyncio.isfuture(type(f)))

        # As `isinstance(Mock(Future), Future)` returns `True`
        self.assertTrue(asyncio.isfuture(mock.Mock(type(f))))

        f.cancel() 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:24,代碼來源:test_futures.py

示例3: test_api_calls_return_a_response_when_run_in_sync_mode

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def test_api_calls_return_a_response_when_run_in_sync_mode(self):
        self.client.token = "xoxb-api_test"
        resp = self.client.api_test()
        self.assertFalse(asyncio.isfuture(resp))
        self.assertTrue(resp["ok"]) 
開發者ID:slackapi,項目名稱:python-slackclient,代碼行數:7,代碼來源:test_web_client.py

示例4: test_api_calls_return_a_future_when_run_in_async_mode

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def test_api_calls_return_a_future_when_run_in_async_mode(self):
        self.client.token = "xoxb-api_test"
        self.client.run_async = True
        future = self.client.api_test()
        self.assertTrue(asyncio.isfuture(future))
        resp = await future
        self.assertEqual(200, resp.status_code)
        self.assertTrue(resp["ok"]) 
開發者ID:slackapi,項目名稱:python-slackclient,代碼行數:10,代碼來源:test_web_client.py

示例5: _dispatch

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def _dispatch(self, f, value=None):
        self._check_exhausted()

        if f is None:
            return
        elif asyncio.isfuture(f):
            f.set_result(value)
        elif asyncio.iscoroutinefunction(f):
            self.loop.create_task(f(value))
        else:
            f(value)
            # self.loop.call_soon(functools.partial(f, value)) 
開發者ID:zh217,項目名稱:aiochan,代碼行數:14,代碼來源:channel.py

示例6: __init__

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def __init__(self, identifier, hashable_key, type_spec, target_future):
    """Creates a cached value.

    Args:
      identifier: An instance of `CachedValueIdentifier`.
      hashable_key: A hashable source value key, if any, or `None` of not
        applicable in this context, for use during cleanup.
      type_spec: The type signature of the target, an instance of `tff.Type`.
      target_future: An asyncio future that returns an instance of
        `executor_value_base.ExecutorValue` that represents a value embedded in
        the target executor.

    Raises:
      TypeError: If the arguments are of the wrong types.
    """
    py_typecheck.check_type(identifier, CachedValueIdentifier)
    py_typecheck.check_type(hashable_key, collections.Hashable)
    py_typecheck.check_type(type_spec, computation_types.Type)
    if not asyncio.isfuture(target_future):
      raise TypeError('Expected an asyncio future, got {}'.format(
          py_typecheck.type_string(type(target_future))))
    self._identifier = identifier
    self._hashable_key = hashable_key
    self._type_spec = type_spec
    self._target_future = target_future
    self._computed_result = None 
開發者ID:tensorflow,項目名稱:federated,代碼行數:28,代碼來源:caching_executor.py

示例7: test_mock_from_create_future

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def test_mock_from_create_future(self, klass):
        loop = asyncio.new_event_loop()

        try:
            if not (hasattr(loop, "create_future") and
                    hasattr(asyncio, "isfuture")):
                return

            mock = klass(loop.create_future())
            self.assertTrue(asyncio.isfuture(mock))
        finally:
            loop.close() 
開發者ID:Martiusweb,項目名稱:asynctest,代碼行數:14,代碼來源:test_mock.py

示例8: isfuture

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def isfuture(fut):
        return isinstance(fut, asyncio.Future) 
開發者ID:skylander86,項目名稱:lambda-text-extractor,代碼行數:4,代碼來源:helpers.py

示例9: test_start_stop

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def test_start_stop(self):
        self.assertTrue(asyncio.isfuture(self.order_book_tracker._order_book_snapshot_router_task))
        self.order_book_tracker.stop()
        self.assertIsNone(self.order_book_tracker._order_book_snapshot_router_task)
        self.order_book_tracker.start() 
開發者ID:CoinAlpha,項目名稱:hummingbot,代碼行數:7,代碼來源:test_kraken_order_book_tracker.py

示例10: test_wrap_future

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import isfuture [as 別名]
def test_wrap_future(self):

        def run(arg):
            return (arg, threading.get_ident())
        ex = concurrent.futures.ThreadPoolExecutor(1)
        f1 = ex.submit(run, 'oi')
        f2 = asyncio.wrap_future(f1, loop=self.loop)
        res, ident = self.loop.run_until_complete(f2)
        self.assertTrue(asyncio.isfuture(f2))
        self.assertEqual(res, 'oi')
        self.assertNotEqual(ident, threading.get_ident())
        ex.shutdown(wait=True) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:14,代碼來源:test_futures.py


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