私は、subprocess.callを使ってPythonで外部アプリケーションを実行しようとしています。私が読んだところでは、Popprocess.allを呼び出さない限り、subprocess.callはブロックされませんが、私にとっては、外部アプリケーションが終了するまでブロックされています。これをどうやって解決するのですか?Python subprocess.call blocking
答えて
subprocess
のコードは、実際にはかなりシンプルで読みやすいです。 3.3または2.7バージョン(該当する場合)を見るだけで、それが何をしているのかを知ることができます。
例えば、call
は次のようになります。
def call(*popenargs, timeout=None, **kwargs):
"""Run command with arguments. Wait for command to complete or
timeout, then return the returncode attribute.
The arguments are the same as for the Popen constructor. Example:
retcode = call(["ls", "-l"])
"""
with Popen(*popenargs, **kwargs) as p:
try:
return p.wait(timeout=timeout)
except:
p.kill()
p.wait()
raise
あなたはwait
を呼び出さずに同じことを行うことができます。 Popen
を作成し、wait
を呼び出してはいけません。これはまさにあなたが望むものです。
あなたは誤ったドキュメントを読んでいます。それらによると:
subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
argsで説明されているコマンドを実行します。コマンドが完了するまで待ってから、returncode属性を戻してください。
ああ、大丈夫です。どのようにして、os.spawnlをP_NOWAITオプションで呼び出すという機能を複製するのですか? – dpitch40
@ dpitch40 - http://docs.python.org/2/library/subprocess.html#replacing-the-os-spawn-family。 –
- 1. Pythonのsubprocess.call
- 2. Python subprocess.callとsubprocess.Popen stdout
- 3. TextMate Pythonバンドルnon-blocking
- 4. PHP socket_read/recv blocking pythonのsocket.send
- 5. Blocking Graphics.drawImage
- 6. Tornado non-blocking SMTPクライアント
- 7. Redis Blocking Save
- 8. Haskell hClose blocking
- 9. Blocking Readのスレッディング
- 10. ip address blocking
- 11. CreateProcess blocking - strange behavior
- 12. non-blocking spmd
- 13. Kombu non-blocking way
- 14. Tornado Blocking Code
- 15. jQuery each()non-blocking?
- 16. BufferedInputStreamとBlocking
- 17. パス環境変数subprocess.call
- 18. subprocess.callののenv VAR
- 19. Pythonでsubprocess.callを使用しているマルチファイルstdin(bowtie用)
- 20. 初心者:何百もの引数を持つpython subprocess.call
- 21. python subprocess.call() "そのようなファイルやディレクトリはありません"
- 22. Windows上のPython 2.7.2でsubprocess.call()を使用する際の問題
- 23. Pythonスクリプトでコマンドを実行するsubprocess.callを取得する
- 24. shebangを使用してsubprocess.callでpythonスクリプトを実行
- 25. 混合Python 2.7/3.3環境でのvirtualenvとsubprocess.call()
- 26. Java Non-Blocking IO ObjectStream
- 27. Item delegate from blocking mousePressEvent
- 28. IObservable TakeLast(n)and blocking
- 29. PHP non-blocking soap client
- 30. ruby non-blocking line read
役立つが、納得がいく。 – dpitch40