私は、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. subprocess.callは
- 6. Pythonのsubprocess.callとsubprocess.runの違いは
- 7. Pythonのsubprocess.callに関する不思議
- 8. discordpy、praw、blocking
- 9. Blocking Graphics.drawImage
- 10. Tornado non-blocking SMTPクライアント
- 11. (ERR、中)subprocess.call
- 12. Haskell hClose blocking
- 13. Blocking Readのスレッディング
- 14. ZeroMq recv not blocking
- 15. BufferedInputStreamとBlocking
- 16. jQuery each()non-blocking?
- 17. Redis Blocking Save
- 18. SSLEngine with blocking IO
- 19. non-blocking spmd
- 20. CreateProcess blocking - strange behavior
- 21. ip address blocking
- 22. Kombu non-blocking way
- 23. Tornado Blocking Code
- 24. ffmpeg | sedコマンドのsubprocess.call形式?
- 25. subprocess.callにargを渡す
- 26. パス環境変数subprocess.call
- 27. 、WindowsのCMDパイソンsubprocess.call
- 28. subprocess.callののenv VAR
- 29. PHP non-blocking soap client
- 30. IObservable TakeLast(n)and blocking
役立つが、納得がいく。 – dpitch40