borgend/exprotect.py

Wed, 02 Feb 2022 11:46:05 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Wed, 02 Feb 2022 11:46:05 +0200
changeset 144
31227feaa05a
parent 106
a7bdc239ef62
permissions
-rw-r--r--

Workaround to refresh timer loops on some configurations

#
# Borgend by Tuomo Valkonen, 2018
#
# Except-catching decocators to catch bugs in callbacks
#

import logging

logger=logging.getLogger(__name__)

def protect_noreturn(fn):
    name=fn.__name__
    def wrapper(*args, **kwargs):
        try:
            fn(*args, **kwargs)
        except:
            logger.exception('bug in ' + name)
    return wrapper


def protect_return(default):
    def wrap(fn):
        name=fn.__name__
        def wrapper(*args, **kwargs):
            try:
                return fn(*args, **kwargs)
            except:
                logger.exception('bug in ' + name)
                return default
        return wrapper
    return wrap

mercurial