简体   繁体   English

如何多线程 Flask 服务器和 python 脚本?

[英]How to multithread Flask server and python script?

I have one python script that is used for reading data form COM port and storing the same data in MongoDB.我有一个 python 脚本,用于从 COM 端口读取数据并将相同的数据存储在 MongoDB 中。 On the other side there is Flask server that is used for displaying data from same database on web page.另一方面有 Flask 服务器,用于在网页上显示来自同一数据库的数据。 They are working separately without any problem.他们分开工作没有任何问题。 Is there any way to merge this two programs, like multithreading in python and how to manage this transformation?有没有办法合并这两个程序,比如python中的多线程以及如何管理这种转换? If needed, I can provide source code for both programs.如果需要,我可以提供这两个程序的源代码。

From my understanding, you want to run two python scripts at the same time.据我了解,您想同时运行两个 python 脚本。

Simply create a bash script with following text, (replace script1 & script 2 with file names)只需创建一个带有以下文本的 bash 脚本,(用文件名替换 script1 和 script 2)

python script1.py &
python script2.py &

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM