def stop(self):
"""
Stop aDTN. Make sure the two threads created at start are finished properly.
"""
self._sending = False
try:
while not self._scheduler.empty():
event = self._scheduler.queue.pop()
self._scheduler.cancel(event)
# By now the scheduler has run empty, so join the thread:
self._thread_send.join()
sleep(5)
# Now we just have to join the receiving thread to stop aDTN completely:
self._sniffing = False
self._thread_receive.join()
log_network("stop")
except ValueError: # In case the popped event started running in the meantime...
log_debug("Scheduler is not empty, retry stopping.")
self.stop() # ...call the stop function once more.
评论列表
文章目录