def run_isolated(f, *args):
"""Execute `f(args)` in an isolated environment.
First, uses dill to serialize the function. Unfortunately, pickle is unable
to serialize some functions, so we must serialize and deserialize the
function ourselves.
"""
f_dill = dill.dumps(f)
with Pool(1) as pool:
return pool.apply(_get_function_and_execute, (f_dill, *args))
评论列表
文章目录