Хорошо, если вы откроете site-packages/vpython/no_notebook.py
, вы увидите:
import webbrowser as _webbrowser
Вот и все.
Под капотом то, что он делает в «режиме без ноутбука, эточто он запускает многопоточный локальный HTTP-сервер, который обслуживает некоторый JavaScript, а затем открывает страницу в веб-браузере для подключения к этому серверу.Остальное - просто обмен данными между сервером и клиентом, как и любым другим веб-приложением.
Более подробное объяснение обмена данными можно найти в 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 (во-первых, неудобно использовать обычную интерактивную оболочку), но я думаю, что она работает.