Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Windows10上同时运行多个python代码?_Python_Multiprocessing_Subprocess_Selenium Chromedriver - Fatal编程技术网

如何在Windows10上同时运行多个python代码?

如何在Windows10上同时运行多个python代码?,python,multiprocessing,subprocess,selenium-chromedriver,Python,Multiprocessing,Subprocess,Selenium Chromedriver,我试图在我的Windows10上同时在python3中运行2个脚本,但是脚本连续运行(第一个脚本完成,然后第二个脚本开始) 我已经试着用“&”和“&&”来运行它们,但是没有用。这是我的密码: import subprocess import S1 #script 1 (it opens a chrome page with Selenium) import S2 #script 2 (it opens a chrome page with Selenium) subprocess.run("py

我试图在我的Windows10上同时在python3中运行2个脚本,但是脚本连续运行(第一个脚本完成,然后第二个脚本开始)

我已经试着用“&”和“&&”来运行它们,但是没有用。这是我的密码:

import subprocess
import S1 #script 1 (it opens a chrome page with Selenium)
import S2 #script 2 (it opens a chrome page with Selenium)
subprocess.run("python S1 && python S2", shell=True)
我也尝试过:

import os
from multiprocessing import Process

def script1():
    os.system("S1.py")
def script2():
    os.system("S2.py")

if __name__ == '__main__':
    p = Process(target=script1)
    q = Process(target=script2)
    p.start()
    q.start()
    p.join()
    q.join()
但我得到了相同的结果,脚本连续运行


如何同时运行这两个命令?

尝试在subprocess命令的文件名末尾添加
.py

导入子流程
run(“pythons1.py&&pythons2.py”,shell=True)

Hi@okawo,我试过了,但它仍然先完成S1.py,然后启动S2.py,我尝试同时运行它们。您可以尝试使用asyncio同时运行它们