运行 两个 python 文件一次

Running two python files at once

我有两个 python 文件,一个是 运行 在 pygame 中进行模拟,另一个获取数据并绘制图表。我希望它们在两个单独的 windows 中 运行,但我希望记录数据,因为模拟是 运行ning。我试过多线程,好像不行。

这两个函数都是 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 循环执行时,我最终只是在相同的 window 中重新渲染图形。对我来说效果很好,我可以完全避免多线程。