10

I'm creating a program in Python using Watchdog that watches a set of files and takes actions based on changes. I put the exact example from their site in a file:

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()

Then, I noticed something odd. I have installed watchdog for both Python 2 and Python 3, in the same way (using pip2 install watchdog and pip3 install watchdog), and at the same time. However, when I run the program in Python 2 and 3 and do the same modification once for each, this happens:

$ 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

What I'm wondering is what could cause this behavior and how could I fix it.

This question is not a duplicate of:

Community
  • 1
  • 1
PurkkaKoodari
  • 6,703
  • 6
  • 37
  • 58
  • 1
    Issue was filed on the Github repository: https://github.com/gorakhargosh/watchdog/issues/346 – bastula Apr 11 '16 at 18:36
  • Can you please share more info regarding the env you are running? (which version of python 3, which version of python 2, OS, etc..) are you modifying the script itself in this example? what is the modification? Does this also happen when you pass a path to the script? Meaning - the monitored path is not '.'. – Alonme Dec 14 '19 at 13:03
  • @Alonme The script was unmodified when I ran it in 2015. I'm not getting the problem to occur anymore. I just tried Python 3.7/3.8 and all versions of watchdog from 0.8.0 to 0.10.0. I'm currently on Debian Bullseye with Linux 5.2.0, can't tell what I was on in 2015. – PurkkaKoodari Dec 14 '19 at 18:39

0 Answers0