我如何从另一个python脚本运行一个python脚本,而第二个脚本不中断第一个? [英] How do i run a python script from another python script without the secondary script interrupting the first?

查看:53
本文介绍了我如何从另一个python脚本运行一个python脚本,而第二个脚本不中断第一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有主要的python脚本,我想从我的主文件中调用另一个python脚本,但是,每当执行此操作时,我称之为的脚本都会超过原始脚本.有什么方法可以在后台调用python脚本,以使其不中断控制台中的主脚本?

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?

推荐答案

我为您制作了此脚本,该脚本使用线程和子进程在后台运行其他python脚本(第二脚本不会中断第一个脚本)

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'

这篇关于我如何从另一个python脚本运行一个python脚本,而第二个脚本不中断第一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆