>>> l=[,,,,]
>>> del l[:]#只是删除列表的部分元素,列表仍然存在
>>> l
[, ]
#reactor循环执行的函数
def runUntilCurrent(self):
"""
Run all pending timed calls.
"""
if self.threadCallQueue:#执行线程化队列,在主线程中执行。
# Keep track of how many calls we actually make, as we're
# making them, in case another call is added to the queue
# while we're in this loop.
count = 0
total = len(self.threadCallQueue)
for (f, a, kw) in self.threadCallQueue:
try:
f(*a, **kw)
except:
log.err()
count += 1
if count == total:
break
del self.threadCallQueue[:count]
if self.threadCallQueue:#其他函数可以插入线程化函数
self.wakeUp() # insert new delayed calls now
self._insertNewDelayedCalls()#插入新的延时执行对象 now = self.seconds()#读取系统时间 1970
while self._pendingTimedCalls and (self._pendingTimedCalls[0].time <= now):定时时间到
call = heappop(self._pendingTimedCalls)
if call.cancelled:
self._cancellations-=1
continue if call.delayed_time > 0:
call.activate_delay()#累加延时时间
heappush(self._pendingTimedCalls, call)
continue try:
call.called = 1
call.func(*call.args, **call.kw)#调用延时对象的函数
except:
log.deferr()
if hasattr(call, "creator"):
e = "\n"
e += " C: previous exception occurred in " + \
"a DelayedCall created here:\n"
e += " C:"
e += "".join(call.creator).rstrip().replace("\n","\n C:")
e += "\n"
log.msg(e) if (self._cancellations > 50 and
self._cancellations > len(self._pendingTimedCalls) >> 1):
self._cancellations = 0
self._pendingTimedCalls = [x for x in self._pendingTimedCalls
if not x.cancelled]
heapify(self._pendingTimedCalls) if self._justStopped:
self._justStopped = False
self.fireSystemEvent("shutdown")

twisted的DelayedCall的更多相关文章

  1. twisted reactor calllater实现

    twisted reactor calllater实现 1.      calllater实现代码 测试源码: from twisted.internet import reactor from tw ...

  2. Mina、Netty、Twisted一起学(八):HTTP服务器

    HTTP协议应该是目前使用最多的应用层协议了,用浏览器打开一个网站就是使用HTTP协议进行数据传输. HTTP协议也是基于TCP协议,所以也有服务器和客户端.HTTP客户端一般是浏览器,当然还有可能是 ...

  3. Twisted随笔

    学习了socket后决定尝试使用框架,目标锁定了Twisted. 什么是Twisted? twisted是一个用python语言写的事件驱动的网络框架,他支持很多种协议,包括UDP,TCP,TLS和其 ...

  4. Python 安装Twisted 提示python version 2.7 required,which was not found in the registry

    由于我安装Python64位的,下载后没注册,安装Twisted时老提示“python version 2.7 required,which was not found in the registry ...

  5. Python - twisted web 入门学习之一

    原文地址:http://zhouzhk.iteye.com/blog/765884 python的twisted框架中带了一个web server: twisted web.现在看看怎么用. 一)准备 ...

  6. Twisted

    Twisted是一个事件驱动的网络框架,其中包含了诸多功能,例如网络协议,线程,数据库管理,网络操作,电子邮件等 事件驱动 一,注册事件 二,触发事件 自定义事件框架  event_fram.py # ...

  7. Mina、Netty、Twisted一起学(十):线程模型

    要想开发一个高性能的TCP服务器,熟悉所使用框架的线程模型非常重要.MINA.Netty.Twisted本身都是高性能的网络框架,如果再搭配上高效率的代码,才能实现一个高大上的服务器.但是如果不了解它 ...

  8. Mina、Netty、Twisted一起学(九):异步IO和回调函数

    用过JavaScript或者jQuery的同学都知道,JavaScript特别是jQuery中存在大量的回调函数,例如Ajax.jQuery的动画等. $.get(url, function() { ...

  9. Mina、Netty、Twisted一起学(七):发布/订阅(Publish/Subscribe)

    消息传递有很多种方式,请求/响应(Request/Reply)是最常用的.在前面的博文的例子中,很多都是采用请求/响应的方式,当服务器接收到消息后,会立即write回写一条消息到客户端.HTTP协议也 ...

随机推荐

  1. python--BUG--python socket.error: [Errno 9] Bad file descriptor的解决办法

    这个错误很明显 ,是因为关闭了套接字对象后,又再次去调用了套接字对象,此时套接字链接已经被关闭,不能再去调用,所以才会出现这种错误,复查一下代码,很快就可以解决.

  2. 基于单片机的Wifi温度湿度测量仪

    这次的制作背景是由于单片机课程实训课程要求 刚好手上有块ESP8266-12F的WiFi模块 于是就选择了制作一个基于单片机,使用WiFi传输数据的温湿度采集测量仪 制作过程: 由于有使用过WiFi模 ...

  3. QT中实现应用程序的单例化

    一介绍 通过编写一个QSingleApplication类,来实现Qt程序的单例化,原文的作者是在Windows Vista + Qt4.4 下实现的,不过应用在其他平台上是没问题的.(本文是我在ht ...

  4. Visual Studio 2010 Shortcut

    General Shortcut Description Ctrl-X or Shift-Delete Cuts the currently selected item to the clipboar ...

  5. Redis缓存机制

    Redis介绍 Redis是一款内存高速缓存数据库: 数据模型为:key - value,非关系型数据库使用的存储数据的格式: 可持久化:将内存数据在写入之后按照一定格式存储在磁盘文件中,宕机.断电后 ...

  6. HTTP API网关选择之一Kong介绍

    为什么需要 API 网关 在微服务架构之下,服务被拆的非常零散,降低了耦合度的同时也给服务的统一管理增加了难度.如上图左所示,在旧的服务治理体系之下,鉴权,限流,日志,监控等通用功能需要在每个服务中单 ...

  7. 服务容错保护断路器Hystrix之六:服务熔断和服务降级

    伴随着微服务架构被宣传得如火如荼,一些概念也被推到了我们面前(管你接受不接受),其实大多数概念以前就有,但很少被提的这么频繁(现在好像不提及都不好意思交流了).想起有人总结的一句话,微服务架构的特点就 ...

  8. 服务网关zuul之三:zuul统一异常处理

    我们详细介绍了Spring Cloud Zuul中自己实现的一些核心过滤器,以及这些过滤器在请求生命周期中的不同作用.我们会发现在这些核心过滤器中并没有实现error阶段的过滤器.那么这些过滤器可以用 ...

  9. [转]截图软件分享 - Snipaste

    http://chromecj.com/software/2018-10/1538.html https://zh.snipaste.com/download.html

  10. ocr 文字区域检测及识别

    ocr 文字区域检测及识别 # coding=utf- from PIL import Image, ImageFilter, ImageEnhance from skimage.filters im ...