Python watchdog: How to handle the watched directory being deleted?

48 views
Skip to first unread message

Jeffrey DeLeo

unread,
Dec 8, 2015, 1:31:19 PM12/8/15
to watchdog-python
I am happily using the watchdog package, specifically PollingObserver, to watch directories for file events. It works great - until the directory I am watching is deleted. What then happens is the code that is polling the directory calls stat() on a non-existent directory, and raises an exception. What is the best way to handle this? I don't see how I can catch this exception as it's in a separate thread.

I wonder if it would make sense for DirectorySnapshot to be None if the directory does not (or no longer) exists?
Reply all
Reply to author
Forward
0 new messages