Python Watchdog:为什么我的子进程连续调用?

时间:2012-09-03 15:40:43

标签: python subprocess watchdog unison

我是Python&的新手我正试图与我的家庭服务器同步自动化。我发现了看门狗&我正在尝试使用它,但每当我运行“touch test.txt”时,脚本会不断启动新的统一进程。由于观察者正在使用从Queue继承的类,我认为它应该在它从队列顶部弹出第一个事件后才阻塞。我在这里忽略了什么吗?

代码:

#!/usr/bin/python
import sys
import subprocess
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class ChangeHandler(FileSystemEventHandler):
   def on_any_event(self, event):
      subprocess.call(["/usr/bin/unison", "-batch", "-silent", "-ui", "text",
         "default"])

if __name__ == "__main__":
   observer = Observer()
   observer.schedule(ChangeHandler(), '/home/philip', True)
   observer.start()
   try:
      while True:
         time.sleep(1)
   except KeyboardInterrupt:
      observer.stop()
   observer.join()

输出:

props    <-?-> props      /  props    <-?-> props      Documents  props    <-?-> props      Downloads  props    <-?-> props      /  props    <-?-> props      Documents  props    <-?-> props      Downloads  props    <-?-> props      /  props    <-?-> props      Documents  props    <-?-> props      Downloads  props    <-?-> props      /  props    <-?-> props      Documents  props    <-?-> props      Downloads  props    <-?-> props      /  props    <-?-> props      Documents  props    <-?-> props      Downloads  props    <-?-> props      /  props    <-?-> props      Documents  props    <-?-> props      Downloads

1 个答案:

答案 0 :(得分:1)

OP在评论中充分回答了这个问题:

  

使用pyinotify最终了解我正在同步一个目录,同时同时查看文件系统事件的同一目录。当然,除非我在处理事件时暂停Observer / Notifier,否则我将获得多个调用。