From: Nikolaus R. <Nik...@ra...> - 2008-07-25 13:18:08
|
Hello, I am currently trying to implement same failsafe mechanism into my FUSE Python filesystem. My (at first sight straightforward) idea is to mark the filesystem as needing an fsck whenever there is an unhandled exception in my code. The problem is now how to detect such a condition. My first solution was done write a custom function decorator that simply catches all exceptions: def make_it_safe(fn): def wrapped(*a, **kw): try: return fn(*a, **kw) except: mark_fs_dirty() log_the_problem() raise return wrapped and apply it to all FUSE API methods: @make_it_safe def getattr(self, path): ... @make_it_safe def readdir(self, path): ... However, this fails for readdir(), since readdir returns a generator. If there are any problems in readdir, they only appear when the generator is iterated. So this solution doesn't work. My second approach was to define a global exception handler instead: def handle_exceptions(a,b,c): mark_fs_dirty() log_the_problem() sys.excepthook = handle_exceptions However, now the problem is that FUSE Python catches all IOError and OSError exceptions in ErrnoWrapper without reraising them. So I am not able to detect all errors. I have thought about this for a while now, and the only solution that I can come up with is to reraise the Exceptions in ErrnoWrapper. Csaba, would such a change be possible? I can imagine that this will make it more difficult to return the correct errno... Best, -Nikolaus -- »It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.« -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C |