tornado : 异步、非阻塞
The terms asynchronous and non-blocking are closely related and are often used interchangeably, but they are not quite the
same thing.
Blocking
A function blocks when it waits for something to happen before returning. A function may block for many reasons: network I/O,
disk I/O, mutexes, etc. In fact, every function blocks, at least a little bit, while it is running and using the CPU (for an extreme
example that demonstrates why CPU blocking must be taken as seriously as other kinds of blocking, consider password hashing
functions like bcrypt, which by design use hundreds of milliseconds of CPU time, far more than a typical network or disk access).
A function can be blocking in some respects and non-blocking in others. For example,tornado.httpclient
in the default
configuration blocks on DNS resolution but not on other network access (to mitigate this use ThreadedResolver
or a
tornado.curl_httpclient
with a properly-configured build of libcurl
). In the context of Tornado we generally talk about
blocking in the context of network I/O, although all kinds of blocking are to be minimized.
Asynchronous
An asynchronous function returns before it is finished, and generally causes some work to happen in the background before triggering
some future action in the application (as opposed to normal synchronous functions, which do everything they are going to do before
returning). There are many styles of asynchronous interfaces:
- Callback argument
- Return a placeholder (
Future
,Promise
,Deferred
) - Deliver to a queue
- Callback registry (e.g. POSIX signals)
Regardless of which type of interface is used, asynchronous functions by definition interact differently with their callers; there is no free
way to make a synchronous function asynchronous in a way that is transparent to its callers (systems like gevent use lightweight threads
to offer performance comparable to asynchronous systems, but they do not actually make things asynchronous).
参考:
tornado : 异步、非阻塞的更多相关文章
- Tornado异步非阻塞的使用以及原理
Tornado 和现在的主流 Web 服务器框架(包括大多数 Python 的框架)有着明显的区别:它是非阻塞式服务器,而且速度相当快.得利于其 非阻塞的方式和对 epoll 的运用,Tornado ...
- Python web框架 Tornado异步非阻塞
Python web框架 Tornado异步非阻塞 异步非阻塞 阻塞式:(适用于所有框架,Django,Flask,Tornado,Bottle) 一个请求到来未处理完成,后续一直等待 解决方案: ...
- Tornado 异步非阻塞
1 装饰器 + Future 从而实现Tornado的异步非阻塞 class AsyncHandler(tornado.web.RequestHandler): @gen.coroutine def ...
- Python3的原生协程(Async/Await)和Tornado异步非阻塞
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_113 我们知道在程序在执行 IO 密集型任务的时候,程序会因为等待 IO 而阻塞,而协程作为一种用户态的轻量级线程,可以帮我们解决 ...
- Tornado的异步非阻塞
阻塞和非阻塞Web框架 只有Tornado和Node.js是异步非阻塞的,其他所有的web框架都是阻塞式的. Tornado阻塞和非阻塞两种模式都支持. 阻塞式: 代表:Django.Flask.To ...
- 150行代码搭建异步非阻塞Web框架
最近看Tornado源码给了我不少启发,心血来潮决定自己试着只用python标准库来实现一个异步非阻塞web框架.花了点时间感觉还可以,一百多行的代码已经可以撑起一个极简框架了. 一.准备工作 需要的 ...
- 使用tornado让你的请求异步非阻塞
http://www.dongwm.com/archives/shi-yong-tornadorang-ni-de-qing-qiu-yi-bu-fei-zu-sai/?utm_source=tuic ...
- 异步非阻塞IO的Python Web框架--Tornado
Tornado的全称是Torado Web Server,从名字上就可知它可用作Web服务器,但同时它也是一个Python Web的开发框架.最初是在FriendFeed公司的网站上使用,FaceBo ...
- 03: 自定义异步非阻塞tornado框架
目录:Tornado其他篇 01: tornado基础篇 02: tornado进阶篇 03: 自定义异步非阻塞tornado框架 04: 打开tornado源码剖析处理过程 目录: 1.1 源码 1 ...
- tornado 之 异步非阻塞
异步非阻塞 1.基本使用 装饰器 + Future 从而实现Tornado的异步非阻塞 import tornado.web import tornado.ioloop from tornado im ...
随机推荐
- 在recycler中写的布局不起作用
把 LinearLayout 改成 RelativeLayout ok了 创建的两种方式 1.LayoutInflater.from(parent.getContext()).inflate(R. ...
- warning C4305:“初始化”:从“double”到“float”截断
编译VS项目时出现警告: warning C4305:“初始化”:从“double”到“float”截断(warning C4305: 'initializing' : truncation from ...
- 在线电路编程 (ICP)
通过在线电路编程(ICP)编程Flash.如果产品在开发中,或在终端客户的产品需要固件升级,采用硬件编程模式非常困难且不方便.采用ICP方式将很简单,且不需要将微控制器从板上拆下来.ICP方式同样允许 ...
- Android 自定义 View 浅析
Android 自定义 View 浅析 概括 说到自定义 View ,就一定得说说 android 系统的UI绘制流程.再说这个流程之前,我们先看一下在每一个 activity 页面中我们的布局 ui ...
- Androidの疑难杂症之加载布局报Error inflating class <unknown>
android.view.InflateException: Binary XML file line #12: Error inflating class <unknown> 出现这种错 ...
- Python操作MySQL数据库的三种方法
https://blog.csdn.net/Oscer2016/article/details/70257024 1. MySQLdb 的使用 (1) 什么是MySQLdb? MySQLdb 是用 ...
- c++ 类内static成员初始化
类内部的static成员,除了为const static 且为整数类型(int char bool)可在类内部初始化. 其他的都建议在对应的cpp文件中进行初始化. test.h #ifndef TE ...
- powerDesigner根据sql脚本来逆向生成pdm等模型
一.问题概述 网上一般的博文都是说要建立数据源的方式来逆向或者正向. 我这人比较懒得折腾,更喜欢通过sql脚本的方式来做. 二.步骤 File-->New Model--> 然后: 注意上 ...
- 问题记录 为ubuntu16.04添加windows字体(解决JIRA图表乱码的问题)
最近遇到了JIRA在新的ubuntu机器上图表的中文无法正确显示的问题,解决的方法是,为ubuntu安装中文字体,我们选择把windows上的字体复制到ubuntu上来安装的方法,步骤如下: 从win ...
- linux shell中curl 发送post请求json格式问题
今天在linux中使用curl发送一个post请求时,带有json的数据,在发送时发现json中的变量没有解析出来 如下 curl -i -X POST -H 'Content-type':'appl ...