concurrency.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:defuse_division 作者: lelandbatey 项目源码 文件源码
def concurrent(f):
    """Concurrent is a decorator for a function which will cause that function
    to immediately return when called, but be left running in 'in the
    background'. It is intended as a functional equivelent to the 'go func()'
    syntax in the Go programming language."""
    def err_logger(*args, **kwargs):
        '''
        err_logger logs uncaught exceptions, which is nice to have in long
        running processes in other threads.
        '''
        try:
            f(*args, **kwargs)
        except Exception as e:
            logging.error(e, exc_info=True)

    def rv(*args, **kwargs):
        t = threading.Thread(target=err_logger, args=(args), kwargs=kwargs)
        t.daemon = True
        t.start()
    return rv
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号