[英]Run multiple python scripts, that use user inputs and while loops, simultaneously
Basically I need to run three files simultaneously and independently. 基本上我需要同时独立运行三个文件。 These files are started with a user input followed by an infinite While Loop. 这些文件以用户输入开始,后跟无限的While循环。
I have found some questions similar to mine but the solutions do not quite fit my needs. 我发现了一些类似于我的问题,但解决方案并不符合我的需求。 I am still a beginner. 我还是个初学者。
I have already tried: 我已经尝试过了:
python device1.py &
python device2.py &
python device3.py
I also tried doing this all in one file but the file is rather large and complicated, and have not succeeded thus far. 我也尝试在一个文件中执行此操作,但文件相当大且复杂,到目前为止还没有成功。
#some code that creates a csv
#input
device = input("input which device you want to connect to")
def function():
#write to csv file from data
while True:
#get live data from device
#csv function
function()
I expect to enter 3 inputs for my 3 scripts, they run their loops, I end the code and have 3 csv files. 我希望为我的3个脚本输入3个输入,它们运行它们的循环,我结束代码并拥有3个csv文件。
Have you tried setting the input in your command? 您是否尝试过在命令中设置输入?
echo inputForDevice1 | python device1.py &
echo inputForDevice2 | python device2.py &
echo inputForDevice3 | python device3.py &
Also remember to detach from the last python call ( python device3.py &
), otherwise you'll be stuck in the infinite loop. 还记得从最后一个python调用( python device3.py &
)分离,否则你将陷入无限循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.