同时运行两个python文件



我有两个python文件,一个在pygame中运行模拟,另一个获取数据和图形。我希望它们在两个独立的窗口中运行,但我希望在模拟运行时记录数据。我试过多线程,它似乎不工作。

两个函数都是while true循环,我希望它们并行运行。

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循环执行时在同一个窗口中重新渲染图形。对我来说足够好了,我可以完全避免多线程。

最新更新