gutil.py 文件源码

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

项目:bcloud 作者: wangYanJava 项目源码 文件源码
def async_call(func, *args, callback=None):
    '''Call `func` in background thread, and then call `callback` in Gtk main thread.

    If error occurs in `func`, error will keep the traceback and passed to
    `callback` as second parameter. Always check `error` is not None.
    '''
    def do_call():
        result = None
        error = None

        try:
            result = func(*args)
        except Exception:
            error = traceback.format_exc()
            logger.error(error)
        if callback:
            GLib.idle_add(callback, result, error)

    thread = threading.Thread(target=do_call)
    thread.daemon = True
    thread.start()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号