import time from watchdog.observers import Observer from watchdog.observers.polling import PollingObserver from watchdog.events import FileSystemEventHandler class Handler(FileSystemEventHandler): pass observer = PollingObserver() observer.schedule(Handler(), "path/to/directory", recursive=True) observer.start() while observer.is_alive(): time.sleep(1) observer.stop() observer.join()In this example, a `PollingObserver` is created and set to monitor a directory for changes. The observer is started and the program waits for the observer to stop running by checking the `is_alive` method in a while loop. Once the observer has stopped, the `stop` method is called to terminate the observer's thread, and the `join` method is used to wait for the thread to join the main program's thread. Overall, the `watchdog` package is a useful tool for monitoring directory changes in Python, and the `Observer` class provides a simple way to track whether or not the observer's thread is still running.