Execute multiple .py files at the same time

前端 未结 1 592
南方客
南方客 2020-12-10 08:30

I have three .py files that I want to run at the same time in a Python script file. I initially called subprocess.call() three times (once for each .py file) bu

相关标签:
1条回答
  • 2020-12-10 09:17

    If you want to use multiprocessing, you can try this:

    import multiprocessing
    
    def worker(file):
        # your subprocess code
    
    
    if __name__ == '__main__':
        files = ["path/to/file1.py","path/to/file2.py","path/to/file3.py"]
        for i in files:
            p = multiprocessing.Process(target=worker, args=(i,))
            p.start()
    
    0 讨论(0)
提交回复
热议问题