【问题标题】:What is the output of a VPython Script? Why does it open in Chrome for me?VPython 脚本的输出是什么?为什么它会在 Chrome 中为我打开?
【发布时间】:2019-06-24 08:16:29
【问题描述】:

每当我使用 vpython 库运行脚本时,可视化都会在 google chrome 选项卡中打开。

我想知道为什么会这样,以及 vpython 可视化的输出是什么让它在 Chrome 选项卡中打开。

【问题讨论】:

    标签: python vpython


    【解决方案1】:

    好吧,如果你打开site-packages/vpython/no_notebook.py,你会看到:

    import webbrowser as _webbrowser
    

    就是这样。

    在后台,它在“无 jupyter 笔记本模式”下所做的是启动一个线程化的本地 HTTP 服务器,该服务器提供一些 javascript,然后在您的网络浏览器中打开一个页面以连接到该服务器。其余的只是服务器和客户端之间的数据交换,就像任何其他 Web 应用程序一样。

    更详细的数据交换说明见site-packages/vpython/vpython.py

    # Now there is no threading in Jupyter VPython. Data is sent to the
    # browser from the trigger() function, which is called by a
    # canvas_update event sent to Python from the browser (glowcomm.js), currently
    # every 33 milliseconds. When trigger() is called, it immediately signals
    # the browser to set a timeout of 33 ms to send another signal to Python.
    # Note that a typical VPython program starts out by creating objects (constructors) and
    # specifying their attributes. The 33 ms signal from the browser is adequate to ensure
    # prompt data transmissions to the browser.
    
    # The situation with non-notebook use is similar, but the http server is threaded,
    # in order to serve glowcomm.html, jpg texture files, and font files, and the
    # websocket is also threaded.
    
    # In both the notebook and non-notebook cases output is buffered in baseObj.updates
    # and sent as a block to the browser at render times.
    

    老实说,我不认为 vpython 的模型是一个好的 API 模型(一方面,在普通的交互式 shell 中使用它很尴尬),但我想它可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-26
      • 2020-07-15
      相关资源
      最近更新 更多