python - 一次运行两个 python 文件
问题描述
我有两个 python 文件,一个在 pygame 中运行模拟,另一个获取数据并绘制图表。我希望它们在两个单独的窗口中运行,但我希望在模拟运行时记录数据。我已经尝试过多线程,但它似乎不起作用。
这两个函数都只是真正的循环,我希望它们并行运行。
def main():
while True:
clock.tick(simSpeed)
# quit function
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
pendulum.update()
drawWindow(screen, pendulum)
threading.Thread(target=main).start()
threading.Thread(target=graphData).start()
def graphData():
while True:
x = data.data["x"]
y = data.data["y"]
plot1 = plt.figure(1)
plt.title("poopyhead")
plt.plot(y, x)
plot2 = plt.figure(5)
plt.plot(x, y)
plot1.clear()
plot2.clear()
plt.show()
time.sleep(1)
解决方案
感谢大家的帮助。每次执行 while 循环时,我最终只是在同一个窗口中重新渲染图形。对我来说效果很好,我可以完全避免多线程。
推荐阅读
- flutter - Flutter - 不可滚动的网格
- php - 如何安排多个具有抽象的类?
- delphi - 如何在特定的警告代码上停止 Delphi 编译器?
- javascript - JS:在函数外存储结果和访问
- javascript - 如何使用 Selenium Java 单击警报弹出窗口中的复选框
- encode - 长度值编码
- java - 我如何知道 java 方法的返回值?
- python - 如何将变量中的字母列表存储为字符串
- bash - 脚本 bash 始终是一个日志文件,当匹配特定单词时,发送邮件
- sass - 是否可以从 VS Code 中的连接文件中启用 SASS / Less 混合和变量的自动完成功能?