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的更多相关文章

  1. Python标准模块--asyncio

    1 模块简介 asyncio模块作为一个临时的库,在Python 3.4版本中加入.这意味着,asyncio模块可能做不到向后兼容甚至在后续的Python版本中被删除.根据Python官方文档,asy ...

  2. Asyncio中的Task管理

    #!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time from random ...

  3. 使用Asyncio的Coroutine来实现一个有限状态机

    如图: #!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time from ra ...

  4. 在PYTHON3中,使用Asyncio来管理Event loop

    #!/usr/bin/env python # -*- coding: utf-8 -*- import asyncio import datetime import time def functio ...

  5. Python asyncio库的学习和使用

    因为要找工作,把之前自己搞的爬虫整理一下,没有项目经验真蛋疼,只能做这种水的不行的东西...T  T,希望找工作能有好结果. 之前爬虫使用的是requests+多线程/多进程,后来随着前几天的深入了解 ...

  6. python asyncio笔记

    1.什么是coroutine coroutine,最早我是在lua里面看到的,coroutine最大的好处是可以保存堆栈,让程序得以继续执行,在python里面,一般是利用yield来实现,具体可以看 ...

  7. Tornado (and Twisted) in the age of asyncio》

    Tornado (and Twisted) in the age of asyncio>

  8. 【译】深入理解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% ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. 根据设备宽高设置View的大小

    得到设备屏幕宽高: WindowManager wManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); ...

  2. centos7部署fabric-ca错误解决

    1.fabric-ca 编译错误:ltdl.h: no such file 在fabric-ca目录中使用make编译时,会出现如下错误: 解决方案: 如果在ubunt操作系统中,只需安装:apt i ...

  3. Linux-pkill命令

    pkill命令可以按照进程名杀死进程.pkill和killall应用方法差不多,也是直接杀死运行中的程序:如果您想杀掉单个进程,请用kill来杀掉. 语法:pkill(选项)(参数) 选项 -o:仅向 ...

  4. PageHelper分页插件

    在mybatis配置文件(SqlMapConfig.xml)中配置 <?xml version="1.0" encoding="UTF-8" ?> ...

  5. [Python] Frequently used method or solutions for issues

    Web Scraping爬虫 for Mac urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] cer ...

  6. [LeetCode] 405. Convert a Number to Hexadecimal_Easy tag: Bit Manipulation

    Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s compl ...

  7. U盘复制文件到最后5秒会卡住怎么办解决

    现在的U盘容量已经非常大了,一般都有16G以上,为了能放单文件大于4G的数据大多数时候我们都是把U盘格式化为ntfs格式的,所以会出现不管是大文件还是小文件,当你往U盘里复制文件或者使用发送到U盘功能 ...

  8. React对比Vue(04 父子组件的通信 )

    跟vue差不多 都是props,但是react里面不仅可以给子组件传值,还可以传方法,MD尽然还可以把自己传给子组件,(卧槽vue可没有这个啊 )  vue的传递值差不多,传方法就不用了,子组件可以掉 ...

  9. opencv-resize()放缩函数简介

    主要介绍函数resize(); 图像缩放的效果图如下: 主程序代码及函数解释如下所示: /******************************************************* ...

  10. CSU 1862 The Same Game(模拟)

    The Same Game [题目链接]The Same Game [题目类型]模拟 &题解: 写这种模拟题要看心态啊,还要有足够的时间,必须仔细读题,一定要写一步,就调试一步. 这题我没想到 ...