python asyncio future_Python asyncio.isfuture方法代码示例

本文整理汇总了Python中asyncio.isfuture方法的典型用法代码示例。如果您正苦于以下问题:Python asyncio.isfuture方法的具体用法?Python asyncio.isfuture怎么用?Python asyncio.isfuture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块asyncio的用法示例。

在下文中一共展示了asyncio.isfuture方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_isfuture

​点赞 6

# 需要导入模块: 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,

示例2: test_isfuture

​点赞 6

# 需要导入模块: 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,

示例3: test_api_calls_return_a_response_when_run_in_sync_mode

​点赞 5

# 需要导入模块: 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,

示例4: test_api_calls_return_a_future_when_run_in_async_mode

​点赞 5

# 需要导入模块: 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,

示例5: _dispatch

​点赞 5

# 需要导入模块: 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,

示例6: __init__

​点赞 5

# 需要导入模块: 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,

示例7: test_mock_from_create_future

​点赞 5

# 需要导入模块: 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,

示例8: isfuture

​点赞 5

# 需要导入模块: import asyncio [as 别名]

# 或者: from asyncio import isfuture [as 别名]

def isfuture(fut):

return isinstance(fut, asyncio.Future)

开发者ID:skylander86,项目名称:lambda-text-extractor,代码行数:4,

示例9: test_start_stop

​点赞 5

# 需要导入模块: 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,

示例10: test_wrap_future

​点赞 5

# 需要导入模块: 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,

注:本文中的asyncio.isfuture方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/334020.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python爬取网站的图片

python爬取网站的图片 本次爬取图片所需要用到的库:Requests库,BeautifulSoup库,正则表达式,os库。 思路:先爬一张图片,再爬一个网站的图片 先爬一张图片: 首先要得到这张图片的地址&#x…

spring 定时器注释_带注释的控制器– Spring Web / Webflux和测试

spring 定时器注释Spring Webflux和Spring Web是两个完全不同的Web堆栈。 但是, Spring Webflux继续支持基于注释的编程模型 使用这两个堆栈定义的端点可能看起来很相似,但是测试这种端点的方式却完全不同,并且编写这种端点的用户必须知道哪…

python计算方位角_实例讲解:用python 计算方位角(根据两点的坐标计算)记得收藏哦...

今天为大家分享一篇python 计算方位角实例(根据两点的坐标计算),具有很好的参考价值,希望对大家有所帮助。一起来看看吧!知道两点坐标,怎么计算两点方向的方位角?答:首先计算坐标增量dx,dy(两个…

Java 中的自举类,到底是什么?

欲知详情,猛戳:https://www.zhihu.com/question/447748200

数据库考研SQL操作

SQL的动词 SQL功能动词数据查询SELECT数据定义CREATE, DROP, ALTER数据操纵INSERT, UPDATE, DELETE数据控制GRANT, REVOKE 注:以下[ ]表示方括号的内容可要可不要,|表示或,//表示注释。 一、数据定义 1.CREATE 定义模式 CREATE SCHEMA &…

objects jdk8_JDK 9:NotNullOrElse方法已添加到Objects类

objects jdk8JDK 9向Objects类添加了一些新方法&#xff0c;包括本文中突出显示的两个static方法&#xff1a; requireNonNullElse&#xff08;T&#xff0c;T&#xff09;和requireNonNullElseGet&#xff08;T obj&#xff0c;Supplier <&#xff1f;extended T>供应商…

用户登陆_华为路由器AAA用户密码登陆你了解吗?

AAA Authentication&#xff08;认证&#xff09;、Authorization&#xff08;授权&#xff09;、Accounting&#xff08;&#xff09;它提供了认证、授权、计费三种安全功能,可以验证用户帐户是否合法&#xff0c;授权用户可以访问的服务&#xff0c;并记录用户使用网络资源的…

Java API 文档中的接口方法和抽象方法,有什么区别?

欲知详情&#xff0c;猛戳&#xff1a;https://www.zhihu.com/question/445956288

java程序设置jvm_Java程序员应在2018年学习的3种JVM语言

java程序设置jvm如果您是Java程序员&#xff0c;并且想学习更多的编程语言以扩展您的知识和技能&#xff0c;但是不确定选择哪种编程语言&#xff0c;那么您来对地方了。 在本文中&#xff0c;我将分享Java程序员可以在2018年学习的3种JVM语言以及为什么要学习它们。 成为多语种…

word域变成正常文本_【Word小技巧】不学会后悔哦~

工作中使用Word早已成了习惯&#xff0c;因此&#xff0c;今天小编将为大家分享几个实用的的Word小技巧。重叠字快速录入文字录入是word最基本操作&#xff0c;过程中我们难免要输入重叠字&#xff0c;例如&#xff1a;热热闹闹&#xff0c;卿卿我我等……你知道如何快速录入吗…

Java 中把声明变量的语句如果写在循环体内,每次执行时栈内存中的变量和数据是如何变化的?

问题一&#xff1a;如下面的代码示例 1&#xff0c;JVM 是不是会反复回收旧的变量 a 再重新创建新的变量 a 呢&#xff1f;还是旧的变量 a 一直保留在栈内&#xff0c;只是反复赋值 0 而已呢&#xff1f; 代码示例 1&#xff1a; while (true) { int a 0; a 5; }问题二&…

使用Speedment 3.0.17及更高版本简化了事务

交易次数 有时我们想确保我们的数据库操作是原子执行的&#xff0c;并且与其他操作分开。 这是交易起作用的地方。 交易是一组操作 数据库可能接受或不接受作为原子操作的建议。 因此&#xff0c;要么接受交易中的所有操作&#xff0c;要么不接受交易中的所有操作。 事务的另一…

python中常用的方法

python常用方法 字符串&#xff1a; name.title() #字符串的每个单词首字母大写 name.upper() #字符串的字母全部大写 name.lower() #字符串的字母全部小写 name.rstrip() #删除字符串结尾的空白 name.lstrip() #删除字符串开头的空白 name.strip() #删除…

sql server 2008 年累计数_Windows Server 2008 和 SQL Server 2008将终止支持 迁移至Azure 微软提供3年免费技术支持...

点击上方蓝色字关注我们~迁移至 Azure 并利用免费扩展安全更新。了解有关支持终止建议的更多信息&#xff0c;请使用浏览器访问&#xff1a;https://www.microsoft.com/zh-cn/sql-server/sql-server-2008.对您意味着什么1 2017年基于风险的安全报告; 思科 2017 年度网络安全报告…

递归调用方法时栈内存是如何变化的?(使用内存图演示递归调用过程)

文章目录 什么是栈内存演示方法递归调用过程什么是栈内存 在学习递归实现原理之前,我们先了解一下栈内存。 栈内存是计算机中的一种数据存储方式,是 Java 进程启动时候在内存中开辟的存储空间。 栈内存的利用方式遵循 LIFO(后迚先出)原则Java 所有局部变量都在栈中分配(压入…

旧版Requests库

requests库基本使用Requests解析库方法response对象response对象的属性**r.encoding**属性与**r.apparent_encoding**属性的区别requests库的异常举例Requests解析库 方法 最常用的两个方法: request.get() request.post() 作用&#xff1a;都是从服务器获取网页信息 区别&…

运行单个源文件_使用一个命令执行单个Java源文件

运行单个源文件JDK增强提案 &#xff08; JEP &#xff09; 草案于2017年末创建&#xff0c;名为“ 启动单文件源代码程序 ”&#xff08;其相关的JDK问题为JDK-8192920 &#xff09;。 顾名思义&#xff0c;该JEP草案旨在“增强Java启动器以支持运行作为Java源代码的单个文件提…

夸克浏览器怎么安装脚本_iOS 第一浏览器发布安卓版,除了真香我还能说什么...

如果不算 Safari 的话&#xff0c;iOS 平台公认最好的浏览器是 Alook。无推送无新闻无广告、日常售价 12 元、工具类排行第三、7.8 万个评分足以证明其优秀。以至于很多双持或对 Alook 有所了解的用户都希望 Alook 能推出安卓端。现在安卓端真的来了。(安卓端免费)假如这个时候…

Windows 10 笔记本如何使用外接显示器

文章目录如何连接外接显示屏如何设置显示模式如何设置不同显示屏各自的分辨率如何设置主显示器通过显卡来设置显示器如何连接外接显示屏 VGA 线或者 HDMI 线连接好电脑和显示器&#xff0c;以 HDMI 线为例简单讲下吧。 显示器可能会有多个 HDMI 接口&#xff0c;假设你插入 H…

蓝牙信号强度检测app_基于蓝牙技术的智能插座方案

有这样一句话“科技时代&#xff0c;生活轻快”。随着社会现代化程度越来越高&#xff0c;科技的应用为人们的生活带来便捷&#xff0c;大大提高了工作效率。纵观市场上“智能家居”产品很多&#xff0c;功能各异&#xff0c;各有千秋&#xff0c;但是针对家电控制的智能插座还…