common.py 文件源码

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

项目:tmtk 作者: thehyve 项目源码 文件源码
def launch_arborist_gui(json_data: str, height=650):
    """

    :param json_data:
    :param height:
    :return:
    """

    new_temp_dir = tempfile.mkdtemp()
    tmp_json = os.path.join(new_temp_dir, 'tmp_json')

    with open(tmp_json, 'w') as f:
        f.write(json_data)

    # Signal created by Javascript to continue work here.
    done_signal = os.path.join(os.path.dirname(tmp_json), 'DONE')

    base_url = os.environ.get("ARBORIST_BASE_URL", "/")

    running_on = '{}transmart-arborist?treefile={}'.format(base_url, os.path.abspath(tmp_json))
    display(IFrame(src=running_on, width='100%', height=height))

    try:
        # Wait for the done signal file to be created before breaking the GIL.
        while not os.path.exists(done_signal):
            time.sleep(0.1)

    except KeyboardInterrupt:
        # This stops the interpreter without showing a stacktrace.
        pass

    else:
        updated_json = None

        # We've been having issues with a slow file system where the json response was empty
        # Now we make sure something is sent back.
        while not updated_json:
            time.sleep(0.1)
            with open(tmp_json, 'r') as f:
                updated_json = f.read()

        return updated_json

    finally:
        shutil.rmtree(new_temp_dir)
        # Clear output from Jupyter Notebook cell
        clear_output()
        print('Cleaning up before closing...')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号