Pur*_*ari 8 python python-2.x python-3.x python-watchdog
我正在使用Watchdog在Python中创建一个程序,该程序监视一组文件并根据更改采取操作.我把他们网站上的确切示例放在一个文件中:
import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
path = sys.argv[1] if len(sys.argv) > 1 else '.'
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
Run Code Online (Sandbox Code Playgroud)
然后,我注意到一些奇怪的事情 我以相同的方式为Python 2和Python 3安装了看门狗(使用pip2 install watchdog和pip3 install watchdog).然而,当我运行在Python 2和3的程序,做同样的修改一次每个,出现这种情况:
$ python2 watch_test.py
2015-09-30 11:18:32 - Modified file: ./watch_test.py
$ python3 watch_test.py
2015-09-30 11:18:39 - Modified file: ./watch_test.py
2015-09-30 11:18:39 - Modified file: ./watch_test.py
2015-09-30 11:18:39 - Modified file: ./watch_test.py
Run Code Online (Sandbox Code Playgroud)
我想知道的是什么可能导致这种行为,我该如何解决它.
这个问题 不是重复的:
| 归档时间: |
|
| 查看次数: |
812 次 |
| 最近记录: |