python2.0_s12_day9_事件驱动编程&异步IO
2016-06-12 10:35
295 查看
论事件驱动与异步IO
事件驱动编程是一种编程范式,这里程序的执行流由外部事件来决定。它的特点是包含一个事件循环,当外部事件发生时使用回调机制来触发相应的处理。另外两种常见的编程范式是(单线程)同步以及多线程编程。让我们用例子来比较和对比一下单线程、多线程以及事件驱动编程模型。下图展示了随着时间的推移,这三种模式下程序所做的工作。这个程序有3个任务需要完成,每个任务都在等待I/O操作时阻塞自身。阻塞在I/O操作上所花费的时间已经用灰色框标示出来了。
<_io.TextIOWrappername='<stderr>'mode='w'encoding='UTF-8'>startinguponlocalhostport10000 1 waitingforthenextevent newconnectionfrom('127.0.0.1',60217) 2 waitingforthenextevent <_io.TextIOWrappername='<stderr>'mode='w'encoding='UTF-8'>received"b'11'"from('127.0.0.1',60217) 3 waitingforthenextevent sending"b'11'"to('127.0.0.1',60217) 4 waitingforthenextevent outputqueuefor('127.0.0.1',60217)isempty 5 waitingforthenextevent closing('127.0.0.1',60217)afterreadingnodata 6 waitingforthenextevent
测试结果
相关文章推荐
- python中MySQLdb模块用法实例
- Python学习路程day19
- python中的not具体使用及意思
- [leetcode]Generate Parentheses 生成圆括号 python实现
- python 遍历select的option选项
- python简单爬虫(一)
- 详解抓取网站,模拟登陆,抓取动态网页的原理和实现(Python,C#等)
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- Python实现N阶台阶的走法问题
- python的高级module工具