worker.py 文件源码

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

项目:ray 作者: ray-project 项目源码 文件源码
def compute_function_id(func_name, func):
    """Compute an function ID for a function.

    Args:
        func_name: The name of the function (this includes the module name plus
            the function name).
        func: The actual function.

    Returns:
        This returns the function ID.
    """
    function_id_hash = hashlib.sha1()
    # Include the function name in the hash.
    function_id_hash.update(func_name.encode("ascii"))
    # If we are running a script or are in IPython, include the source code in
    # the hash. If we are in a regular Python interpreter we skip this part
    # because the source code is not accessible. If the function is a built-in
    # (e.g., Cython), the source code is not accessible.
    import __main__ as main
    if (hasattr(main, "__file__") or in_ipython()) \
            and inspect.isfunction(func):
        function_id_hash.update(inspect.getsource(func).encode("ascii"))
    # Compute the function ID.
    function_id = function_id_hash.digest()
    assert len(function_id) == 20
    function_id = FunctionID(function_id)

    return function_id
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号