utils.py 文件源码

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

项目:ovsdbapp 作者: openstack 项目源码 文件源码
def avoid_blocking_call(f, *args, **kwargs):
    """Ensure that the method "f" will not block other greenthreads.

    Performs the call to the function "f" received as parameter in a
    different thread using tpool.execute when called from a greenthread.
    This will ensure that the function "f" will not block other greenthreads.
    If not called from a greenthread, it will invoke the function "f" directly.
    The function "f" will receive as parameters the arguments "args" and
    keyword arguments "kwargs". If eventlet is not installed on the system
    then this will call directly the function "f".
    """
    if eventlet is None:
        return f(*args, **kwargs)

    # Note that eventlet.getcurrent will always return a greenlet object.
    # In case of a greenthread, the parent greenlet will always be the hub
    # loop greenlet.
    if eventlet.getcurrent().parent:
        return tpool.execute(f, *args, **kwargs)
    else:
        return f(*args, **kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号