简体   繁体   中英

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

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?

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM