Stop reading process output in Python without hang?

前端 未结 5 1239
遇见更好的自我
遇见更好的自我 2020-11-22 14:45

I have a Python program for Linux almost looks like this one :

import os
import time

process = os.popen(\"top\").readlines()

time.sleep(1)

os.popen(\"kill         


        
5条回答
  •  梦谈多话
    2020-11-22 15:14

    What I would do, rather than this approach, is to examine the program you are trying to get information from and determine the ultimate source of that information. It may be an API call or device node. Then, write some python that gets it from the same source. That eliminates the problems and overhead of "scraping" "cooked" data.

提交回复
热议问题