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 (FuturePromiseDeferred)
  • 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 : 异步、非阻塞的更多相关文章

  1. Tornado异步非阻塞的使用以及原理

    Tornado 和现在的主流 Web 服务器框架(包括大多数 Python 的框架)有着明显的区别:它是非阻塞式服务器,而且速度相当快.得利于其 非阻塞的方式和对 epoll 的运用,Tornado ...

  2. Python web框架 Tornado异步非阻塞

    Python web框架 Tornado异步非阻塞   异步非阻塞 阻塞式:(适用于所有框架,Django,Flask,Tornado,Bottle) 一个请求到来未处理完成,后续一直等待 解决方案: ...

  3. Tornado 异步非阻塞

    1 装饰器 + Future 从而实现Tornado的异步非阻塞 class AsyncHandler(tornado.web.RequestHandler): @gen.coroutine def ...

  4. Python3的原生协程(Async/Await)和Tornado异步非阻塞

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_113 我们知道在程序在执行 IO 密集型任务的时候,程序会因为等待 IO 而阻塞,而协程作为一种用户态的轻量级线程,可以帮我们解决 ...

  5. Tornado的异步非阻塞

    阻塞和非阻塞Web框架 只有Tornado和Node.js是异步非阻塞的,其他所有的web框架都是阻塞式的. Tornado阻塞和非阻塞两种模式都支持. 阻塞式: 代表:Django.Flask.To ...

  6. 150行代码搭建异步非阻塞Web框架

    最近看Tornado源码给了我不少启发,心血来潮决定自己试着只用python标准库来实现一个异步非阻塞web框架.花了点时间感觉还可以,一百多行的代码已经可以撑起一个极简框架了. 一.准备工作 需要的 ...

  7. 使用tornado让你的请求异步非阻塞

    http://www.dongwm.com/archives/shi-yong-tornadorang-ni-de-qing-qiu-yi-bu-fei-zu-sai/?utm_source=tuic ...

  8. 异步非阻塞IO的Python Web框架--Tornado

    Tornado的全称是Torado Web Server,从名字上就可知它可用作Web服务器,但同时它也是一个Python Web的开发框架.最初是在FriendFeed公司的网站上使用,FaceBo ...

  9. 03: 自定义异步非阻塞tornado框架

    目录:Tornado其他篇 01: tornado基础篇 02: tornado进阶篇 03: 自定义异步非阻塞tornado框架 04: 打开tornado源码剖析处理过程 目录: 1.1 源码 1 ...

  10. tornado 之 异步非阻塞

    异步非阻塞 1.基本使用 装饰器 + Future 从而实现Tornado的异步非阻塞 import tornado.web import tornado.ioloop from tornado im ...

随机推荐

  1. 3ds Max导出FBX动画模型在OSG中使用

    3ds Max做好动画模型 导出选项:包含-动画-附加选项-勾选使用场景名(这样动画名就是场景名)高级选项-单位-勾选自动(否则导出的模型很小) 导出文件名假设a.fbx使用osgconv工具旋转坐标 ...

  2. 与MQ通讯的完整JAVA程序

    该程序实现了发送消息与读取消息的功能,见其中的 send***与get***方法.这只适合于测试,因为环境中的程序还需要对此有稍微的更改,在真实的环境中肯定是在while(true){...} 的无限 ...

  3. mybatis 之 resultType="HashMap" parameterType="list"

    public ServiceMessage<List<Map<String, Object>>> queryGoodsStockInfo(List<Long& ...

  4. mybatis的selectOne和selectList没有数据返回时的问题

    1.使用mybatis的selectList方法,如果数据表中没有数据返回,则返回空集合[ ],而不会返回null,这是mybatis作的封装 @Override public List<Con ...

  5. C++ sort函数用法 C中的qsort

    需要包含#include <algorithm>MSDN中的定义: template<class RanIt>     void sort(RanIt first, RanIt ...

  6. CSS+transform画动态表情

    先给大家看下画完后是什么样子: 代码看这里: html代码: <body> <div class="emoji emoji_like"> <div c ...

  7. [原]Failed to load SELinux policy. System Freezing ----redhat7or CentOS7 bug

    重启rhel7或者centos7 启动界面按 e 在启动项后面加上enforcing=0 Ctrl+x  运行修改后的grub 进入系统 编辑保存/etc/selinux/config 重启

  8. Dumb Bones UVA - 10529[多米诺重构]

    Dumb Bones UVA - 10529   来自绿书p176  题意 你试图把一些多米诺骨牌排成直线,然后推倒它们.但是如果你在放骨牌的时候不小心把刚放的骨牌碰倒了,它就会把相临的一串骨牌全都碰 ...

  9. vue-loader的简单例子

    一.模块加载器 1.broserify 模块加载器, 只能加载js 2.webpack 模块加载器, 一切东西都是模块, 最后打包到一块 .vue文件  ==> 需要用webpack编译成浏览器 ...

  10. 【CF725G】Messages on a Tree 树链剖分+线段树

    [CF725G]Messages on a Tree 题意:给你一棵n+1个节点的树,0号节点是树根,在编号为1到n的节点上各有一只跳蚤,0号节点是跳蚤国王.现在一些跳蚤要给跳蚤国王发信息.具体的信息 ...