2017-07-30 5 views
0

私はメインのpythonスクリプトを持っていますが、私はメインファイルから別のpythonスクリプトを呼び出したいと思います。バックグラウンドでPythonスクリプトを呼び出す方法はありますか?コンソールのメインスクリプトを中断しないようにする方法はありますか?どのように私は最初の割り込み中の二次スクリプトなしで別のPythonスクリプトからPythonスクリプトを実行するのですか?

+1

確かに(二スクリプトが最初に中断することなく)、バックグラウンドで他のPythonスクリプトを実行するスレッドとサブプロセスを使用して、あなたのためにこのスクリプトを作ります。 –

+0

[ブロックしていないサブプロセス・コール](https://stackoverflow.com/questions/16071866/non-blocking-subprocess-call) –

+0

の複製も可能です。https://stackoverflow.com/questions/16986658/python- call-external-program-non-blocking-way –

答えて

1

こんにちは私は `subprocess`モジュールを学び、

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' 
+0

これは素晴らしいですが、セカンダリスクリプトがコンソールに出力されないようにする方法はありますか? – invisabuble

+0

@invisabubleこれはあなたが検索するか質問するべきかという全く別の質問です。 LMGTFY:https://stackoverflow.com/questions/2125702/how-to-suppress-console-output-in-python#25061573、https://docs.python.org/3.5/library/subprocess.html#subprocessあなたのstdoutとstderrをルーティングするコールのためのkwargがあることを示すコール –

+0

こんにちは、あなたはそれが役に立つと思うことができますhttps://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a -thread-in-python –

関連する問題