PollingObserver reports new symlink as "FileMovedEvent".
Author: maxnoeCreated Jun 10, 2025Updated Aug 15, 2026
Code:
import time
from watchdog.events import FileSystemEvent, FileSystemEventHandler
from watchdog.observers.polling import PollingObserver
class MyEventHandler(FileSystemEventHandler):
def on_any_event(self, event: FileSystemEvent) -> None:
print(event)
event_handler = MyEventHandler()
observer = PollingObserver()
observer.schedule(event_handler, "data", recursive=True)
observer.start()
print("Watchdog running")
try:
while True:
time.sleep(1)
finally:
observer.stop()
observer.join()Commands run in a separate window:
$ cd data
$ mkdir bar
$ touch bar/data
$ cd bar
$ ln -s data data.triggerOutput:
❯ python test_watchdog.py
Watchdog running
DirModifiedEvent(src_path='data', dest_path='', event_type='modified', is_directory=True, is_synthetic=False)
DirCreatedEvent(src_path='data/bar', dest_path='', event_type='created', is_directory=True, is_synthetic=False)
FileCreatedEvent(src_path='data/bar/data', dest_path='', event_type='created', is_directory=False, is_synthetic=False)
DirModifiedEvent(src_path='data/bar', dest_path='', event_type='modified', is_directory=True, is_synthetic=False)
FileMovedEvent(src_path='data/bar/data', dest_path='data/bar/data.trigger', event_type='moved', is_directory=False, is_synthetic=False)
DirModifiedEvent(src_path='data/bar', dest_path='', event_type='modified', is_directory=True, is_synthetic=False)The second to last line is a FileMovedEvent, although what really happend was the creation of a new symlink.
Using the standard Observer, a FileCreatedEvent is send:
DirCreatedEvent(src_path='./data/bar', dest_path='', event_type='created', is_directory=True, is_synthetic=False)
DirModifiedEvent(src_path='./data', dest_path='', event_type='modified', is_directory=True, is_synthetic=False)
FileCreatedEvent(src_path='./data/bar/data', dest_path='', event_type='created', is_directory=False, is_synthetic=False)
DirModifiedEvent(src_path='./data/bar', dest_path='', event_type='modified', is_directory=True, is_synthetic=False)
FileOpenedEvent(src_path='./data/bar/data', dest_path='', event_type='opened', is_directory=False, is_synthetic=False)
FileModifiedEvent(src_path='./data/bar/data', dest_path='', event_type='modified', is_directory=False, is_synthetic=False)
FileClosedEvent(src_path='./data/bar/data', dest_path='', event_type='closed', is_directory=False, is_synthetic=False)
DirModifiedEvent(src_path='./data/bar', dest_path='', event_type='modified', is_directory=True, is_synthetic=False)
FileCreatedEvent(src_path='./data/bar/data.trigger', dest_path='', event_type='created', is_directory=False, is_synthetic=False)
DirModifiedEvent(src_path='./data/bar', dest_path='', event_type='modified', is_directory=True, is_synthetic=False)Source: gorakhargosh/watchdog