How do i run a python script from another python script without the secondary script interrupting the first?

一笑奈何 提交于 2021-01-28 08:24:08

问题


So I have the main python script and I want to call another python script from my main file, however, whenever I do this the script I call kinda overtakes the original. is there any way to call a python script in the background to have it not interrupt the main script in the console?


回答1:


Hi I make this script for you using threading and subprocess to run other python script in the background (without the secondary script interrupting the first)

import threading
from subprocess import call
def thread_second():
    call(["python", "secondscript.py"])
processThread = threading.Thread(target=thread_second)  # <- note extra ','
processThread.start()

print 'the file is run in the background'


来源:https://stackoverflow.com/questions/45403193/how-do-i-run-a-python-script-from-another-python-script-without-the-secondary-sc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!