安装twisted模块

Linux:

  pip3 install twisted

Window:

a. http://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted,

下载:Twisted-17.1.0-cp35-cp35m-win_amd64.whl

b. 进入文件所在目录

c.  pip3 install Twisted-17.1.0-cp35-cp35m-win_amd64.whl

Twisted实例[小有问题]

from twisted.web.client import getPage  # 专门用来发送HTTP请求的
from twisted.web.client import defer
from twisted.internet import reactor # 循环等待用户请求的响应 def all_done(arg):
reactor.stop() def callback(contents):
print(contents) deferred_list = [] url_list = ['http://www.bing.com', 'http://www.baidu.com', ]
for url in url_list:
deferred = getPage(bytes(url, encoding='utf8')) # 加载url交给getPage()
deferred.addCallback(callback) # 回调函数表示请求完成后,需要做的操作
# deferred_list.append(deferred) # # dlist = defer.DeferredList(deferred_list)
# dlist.addBoth(all_done) reactor.run() # de

Python学习---IO的异步[twisted模块]的更多相关文章

  1. Python学习---IO的异步[tornado模块]

    tornado是一个异步非阻塞的WEB框架.它的异步非阻塞实际上就是用事件循环写的. 主要体现在2点: 1. 作为webserver可以接收请求,同时支持异步处理请求.Django只能处理完成上一个请 ...

  2. Python学习---IO的异步[asyncio模块(no-http)]

    Asyncio进行异步IO请求操作: 1. @asyncio.coroutine  装饰任务函数 2. 函数内配合yield from 和装饰器@asyncio.coroutine 配合使用[固定格式 ...

  3. Python学习---IO的异步[gevent+Grequests模块]

    安装gevent模块 pip3 install gevent Gevent实例 import gevent import requests from gevent import monkey # so ...

  4. Python学习---IO的异步[asyncio +aiohttp模块]

    aiohttp aiohttp是在asyncio模块基础上封装的一个支持HTTP请求的模块,内容比8.4.2[基于asyncio实现利用TCP模拟HTTP请求]更全面 安装aiohttp: pip3 ...

  5. Python学习---IO的异步[自定义异步IO]

    自定义IO异步基础知识: --所有的请求都基于socket实现,一个请求就是一个socket socket.setblocking(False) 不需要阻塞,一个请求完了发送另外一个,会报错,需解决 ...

  6. Python学习系列(六)(模块)

    Python学习系列(六)(模块) Python学习系列(五)(文件操作及其字典) 一,模块的基本介绍 1,import引入其他标准模块 标准库:Python标准安装包里的模块. 引入模块的几种方式: ...

  7. python学习第四十八天json模块与pickle模块差异

    在开发过程中,字符串和python数据类型进行转换,下面比较python学习第四十八天json模块与pickle模块差异. json 的优点和缺点 优点  跨语言,体积小 缺点 只能支持 int st ...

  8. Python学习day17-常用的一些模块

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  9. python学习笔记-(九)模块

    基础知识 1. 定义 模块:用来从逻辑上组织python代码(变量,函数,类,逻辑----实现一个功能),本质就是.py结尾的python文件(文件名:test.py,对应的模块就是test) 包:用 ...

随机推荐

  1. WPF根据ScrollViewer的滚动条出现与否来设置触发器Trigger

    先看一段代码 <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource ...

  2. [LeetCode] Level Order Traversal

    题目说明 Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to r ...

  3. [CQOI 2018]九连环

    Description 题库链接 给你一个 \(n\) 连环,游戏规则是: 第一个(最右边)环任何时候都可以任意装上或卸下: 如果第 \(k\) 个环没有被卸下,且第 \(k\) 个环右边的所有环都被 ...

  4. 关于phonegap-plugin-contentsync插件

    插件介绍: 作用:下载并缓存远程托管的内容. 地址:https://github.com/phonegap/phonegap-plugin-contentsync 插件支持的平台:Android.IO ...

  5. unity 中的协程

    //The coroutine will continue after all Update functionshave been calledon the next frame. ; //Conti ...

  6. 点击一个元素,触发另一个元素的click事件

  7. C# 数组中的 indexOf 方法

    var array=['REG','2018','2018']; array.indexOf(‘REG’) // 0 array.indexOf(‘R’) // -1 array.indexOf(’2 ...

  8. 添加List集合覆盖问题

    今天在做一个项目的时候,发现了这样一个问题,为了让大家看得更直接明了,我直接放代码: public void InsertObjectToList(){ List<NewsProtetype&g ...

  9. iOS字体打印

    //打印所以字体    NSArray *familyNames = [UIFont familyNames];    for(NSString *familyName in familyNames) ...

  10. Redis与Memcached简单对比(转)

    很多开发者都认为Redis不可能比Memcached快,Memcached完全基于内存,而Redis具有持久化保存特性,即使是异步的,Redis也不可能比Memcached快.但是测试结果基本是Red ...