I have problems to catch errors inside an event handler from pyinotify. I am trying to do some processing on files that have just been closed after being written to.
Here is a simplified version of my script:
import pyinotify
import asyncore
mask = pyinotify.IN_CLOSE_WRITE
class EventHandler(pyinotify.ProcessEvent):
def process_IN_CLOSE_WRITE(self, event):
try:
do_stuff()
except BaseException as e:
print "Exception:" + str(e)
pass
if __name__ == "__main__":
try:
wm = pyinotify.WatchManager()
notifier = pyinotify.AsyncNotifier(wm, EventHandler())
wdd = wm.add_watch('/dir-to-watch/', mask, rec=True)
asyncore.loop()
except:
print "Unhandled error!"
print "Details:" + str(e)
print "Continuing anyway..."
pass
It seems that when I get an error or an exception neither my except in the main loop or my except BaseException in the event handler are catching the error or exceptions.
I get messages beginning like this:
error: uncaptured python exception, closing channel (:[Errno 2] No such file or directory:
So my question is: how could catch those exceptions?