我无法从pyinotify捕获事件处理程序中的错误。 我正在尝试对写入后刚刚关闭的文件进行一些处理。在
以下是我脚本的简化版本:
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
当我遇到错误或异常时,无论是主循环中的except还是事件处理程序中的except BaseException都没有捕捉到错误或异常。在
我收到的信息是这样开头的:
error: uncaptured python exception, closing channel (:[Errno 2] No such file or directory:
所以我的问题是:怎样才能捕捉到这些异常?在
我必须创建一个自定义的异步通知程序:
然后更改我的代码以使用它:
^{pr2}$相关问题 更多 >
编程相关推荐