python: nonblocking subprocess, check stdout

前端 未结 2 1264
感动是毒
感动是毒 2020-12-16 07:03

Ok so the problem I\'m trying to solve is this:

I need to run a program with some flags set, check on its progress and report back to a server. So I need my script

相关标签:
2条回答
  • 2020-12-16 07:24

    You can use twisted library for this use case. I think it will be great for that

    http://www.cs.lth.se/EDA046/assignments/assignment4/twisted/listings/process/quotes.py

    documentation : http://www.cs.lth.se/EDA046/assignments/assignment4/twisted/process.html

    0 讨论(0)
  • 2020-12-16 07:46

    Basically you have 3 options:

    1. Use threading to read in another thread without blocking the main thread.
    2. select on stdout, stderr instead of communicate. This way you can read just when data is available and avoid blocking.
    3. Let a library solve this, twisted is a obvious choice.
    0 讨论(0)
提交回复
热议问题