I am using the Pyramid web framework to serve a performance model and allow a number of users to use it remotely.
In short, parameters provided by the user are input to an XML file and then the model, which is written in C++ and uses the XML, is executed with subprocess.Popen in a separate view.
The model can take some time and its logging information is valuable to the user. I was hoping I could write each line from the stdout to an HTML file and then generate an iFrame with this file as the source.
Once the subprocess has begun, an iFrame is generated with the HTML file being updated as the source
<iframe id="logSimInlineFrame" src="${request.static_url('fcmod_web:temp/logfile.html')}" Content-Type="text/plain" charset="utf-8"></iframe>
I realize this isn't static and I encounter the following error
ValueError: No static URL definition matching fcmod_web:temp/logfile.html
So my question is, am I on the right track with an iFrame whose content is generated by Python? And if so, how should I provide this data so it is updated dynamically?
Or, and I imagine this to be the case, is there a much more efficient way to stream the data from the stdout PIPE to a frame on the web page?
答案 0 :(得分:2)
IFrame流媒体是最好的hacky。您可以利用与浏览器进行实时通信的技术
Server-sent events - 请参阅Flask example(在金字塔上应该没有什么不同)
AJAX和HTTP长轮询等技术不适用于可流式传输。所有现代浏览器本身都支持WebSockets - 最后一个不支持它们的浏览器是Android 2.2。
对于流媒体,您的普通网络服务器可能无法将其剪切,因此您需要探索,例如uWSGI and Server-Sent event支持。请注意,与WSGI for HTTP不同,Python没有实时通信标准,因此任何解决方案都将特定于您的Web服务器软件。