>>> l=[1,2,3,4,5] >>> del l[:3]#只是删除列表的部分元素,列表仍然存在 >>> l [4, 5]
#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")