Python asyncio.isfuture() Examples
The following are 11
code examples of asyncio.isfuture().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
asyncio
, or try the search function
.
Example #1
Source File: test_futures.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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()
Example #2
Source File: test_futures.py From android_universal with MIT License | 6 votes |
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()
Example #3
Source File: test_web_client.py From python-slackclient with MIT License | 5 votes |
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"])
Example #4
Source File: test_web_client.py From python-slackclient with MIT License | 5 votes |
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"])
Example #5
Source File: channel.py From aiochan with Apache License 2.0 | 5 votes |
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))
Example #6
Source File: caching_executor.py From federated with Apache License 2.0 | 5 votes |
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
Example #7
Source File: test_mock.py From asynctest with Apache License 2.0 | 5 votes |
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()
Example #8
Source File: helpers.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
def isfuture(fut): return isinstance(fut, asyncio.Future)
Example #9
Source File: helpers.py From lambda-text-extractor with Apache License 2.0 | 5 votes |
def isfuture(fut): return isinstance(fut, asyncio.Future)
Example #10
Source File: test_kraken_order_book_tracker.py From hummingbot with Apache License 2.0 | 5 votes |
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()
Example #11
Source File: test_futures.py From android_universal with MIT License | 5 votes |
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)