问题描述
我有一个烧瓶应用程序作为服务器,我有一个 kivy 应用程序作为服务器的前端.如何运行烧瓶然后运行 kivy 应用程序以便它们同时协同工作?
I have a flask app serving as a server and I have a kivy app serving as a front end to a server. How can I run flask and then kivy app so they work together at the same time?
Flask 应用:
Kivy 应用:
更新:如果有人在使用 apache 实现网络服务器时遇到问题,请尝试 docker,我认为这是一种更简单、更快的解决方案!
Update: If someone is having problems implementing a webserver with apache, try docker, simpler and faster solution, in my opinion!
推荐答案
我想让 Flask 连续运行.我尝试了建议的解决方案,按照@amanb 的建议将它们作为线程一起运行.我发现 Flask 正在阻塞 Kivy,反之亦然,无论线程的时间安排或排列方式如何.原因是解释器的 GIL.因此,我尝试了流程,似乎它确实有效.
I wanted Flask to run continuously. I tried the proposed solution to run them together as threads as suggested by @amanb. I found out Flask is blocking Kivy and vice versa no matter the timing or how arranged are the threads. The reason being the interpreter's GIL. Therefore I tried with processes and it seems it does the work.
代码
更新要通过在 Kivy 中按下按钮来按需运行 Flask,我使用下面的脚本.
UPDATE To run Flask on demand by pressing a button in Kivy I use the script below.
这篇关于如何同时运行 kivy 和烧瓶应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!