如何安全地阻止看门狗观察员?

时间:2017-11-30 22:40:06

标签: python python-3.x watchdog python-watchdog

我正试图找到一种方法来安全地停止运行的看门狗事件处理程序。 我的函数是获取一个命令参数,如果一个命令要停止看门狗事件观察者,那么只要它安全地完成任务就应该停止事件和监听器,这意味着我不想中断任务。

如果您就此问题提供支持,我将不胜感激。

谢谢。

更新:1

我试图关注库文档,我的实现如下:

observer.schedule(event_handler, this_cfg.inbound_folder_path)
observer.start()
print('Listening {} folder..........'.format(this_cfg.inbound_folder_path))
try:
   while True:           
        time.sleep(1)
except KeyboardInterrupt:
        observer.stop()
observer.join()

之后我在observer类中找到了一个属性,并改变了如下的实现:

 observer.schedule(event_handler, this_cfg.inbound_folder_path)
 observer.start()
 print('Listening {} folder..........'.format(this_cfg.inbound_folder_path))
 try:
    while (observer.event_queue.unfinished_tasks != 0 and stop_signal!=True):
      time.sleep(1)
    observer.stop()
    observer.join()
  except KeyboardInterrupt:
    observer.stop()

您如何看待我的方法?如果您知道更好的解决方案,我将不胜感激。谢谢

0 个答案:

没有答案