self asyncio
import asyncio
from threading import Thread
import time print('main start:',time.time()) async def download(i):
print(i, time.time())
await asyncio.sleep(i)
b=linkextractor(i)
if b is not None:
await asyncio.wait(b)
else:
print('all complete',time.time())
return True def linkextractor(content):
if content<3:
tasks=[]
tasks.append(download(content+1))
tasks.append(download(content+1))
tasks.append(download(content+1))
return tasks
print('end linkextractor', time.time()) def start_loop(loop):
asyncio.set_event_loop(loop)
loop.run_forever() new_loop=asyncio.new_event_loop()
t=Thread(target=start_loop,args=(new_loop,))
t.start() asyncio.run_coroutine_threadsafe(download(1),new_loop)
self asyncio的更多相关文章
- Python标准模块--asyncio
1 模块简介 asyncio模块作为一个临时的库,在Python 3.4版本中加入.这意味着,asyncio模块可能做不到向后兼容甚至在后续的Python版本中被删除.根据Python官方文档,asy ...
- Asyncio中的Task管理
#!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time from random ...
- 使用Asyncio的Coroutine来实现一个有限状态机
如图: #!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time from ra ...
- 在PYTHON3中,使用Asyncio来管理Event loop
#!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time def functio ...
- Python asyncio库的学习和使用
因为要找工作,把之前自己搞的爬虫整理一下,没有项目经验真蛋疼,只能做这种水的不行的东西...T T,希望找工作能有好结果. 之前爬虫使用的是requests+多线程/多进程,后来随着前几天的深入了解 ...
- python asyncio笔记
1.什么是coroutine coroutine,最早我是在lua里面看到的,coroutine最大的好处是可以保存堆栈,让程序得以继续执行,在python里面,一般是利用yield来实现,具体可以看 ...
- Tornado (and Twisted) in the age of asyncio》
Tornado (and Twisted) in the age of asyncio>
- 【译】深入理解python3.4中Asyncio库与Node.js的异步IO机制
转载自http://xidui.github.io/2015/10/29/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3python3-4-Asyncio%E5%BA%93% ...
- PYTHON ASYNCIO: FUTURE, TASK AND THE EVENT LOOP
from :http://masnun.com/2015/11/20/python-asyncio-future-task-and-the-event-loop.html Event Loop On ...
- Understanding Asynchronous IO With Python 3.4's Asyncio And Node.js
[转自]http://sahandsaba.com/understanding-asyncio-node-js-python-3-4.html Introduction I spent this su ...
随机推荐
- Spark Sql数仓报-Metastore contains multiple versions
Spark版本为2.1.0,Hadoop版本为2.7.1,元数据存储在mysql中,异常信息如下: Exception in thread "main" java.lang.Run ...
- 由ngx.say和ngx.print差异引发的血案
Jan 16, 2018openresty点击 最近上线一个项目,利用openresty在前面做反向代理,部分地址通过lua的http请求后端接口进行返回,在线下测试都没问题,公司预发灰度测试都通过了 ...
- 教你写Makefile(很全,含有工作经验的)
Makefile 值得一提的是,在Makefile中的命令,必须要以[Tab]键开始. 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了 ...
- Tf中的SGDOptimizer学习【转载】
转自:https://www.tensorflow.org/api_docs/python/tf/train/GradientDescentOptimizer 1.tf.train.GradientD ...
- docker 在宿主机上根据进程PID查找归属容器ID
在使用docker时经常出现一台docker主机上跑了多个容器,可能其中一个容器里的进程导致了整个宿主机load很高,其实一条命令就可以找出罪魁祸首 #查找容器ID docker inspect -f ...
- [LeetCode] 504. Base 7_Easy tag: Math
Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...
- CentOS系统 cd命令的使用
直接输入 cd 命令 ,它将切换到你的 home 目录下,不管你当前所在的目录是什么: [ec2-user@ip-*** /]$ cd [ec2-user@ip-*** ~]$ cd /var/www ...
- UGUI之Scrollbar使用
这个效果主要用到了3个组件(对象): 1:Scrollbar对象 滚动条 2:Scroll Rect组件 让对象具有滑动效果 3:Mask组件 遮罩层.把多余的部分隐藏不显示 Scrollbar ...
- shell编程:for循环
有几个参数执行几次 do done取代了{} 这种用于 文件的个数,用户的个数等. (())里才可以进行加减乘除.
- pycharm python3.5 神奇的导入问题
说明:pycharm目录中没有同名.py文件,则可以直接用import util导入: 若有同名.py文件,则导入的时候需要加入所在文件夹名称