Python wait until data is in sys.stdin

后端 未结 9 1297
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 23:00

my problem is the following:

My pythons script receives data via sys.stdin, but it needs to wait until new data is available on sys.stdin.

As described in th

9条回答
  •  心在旅途
    2020-12-15 23:11

    Well i will stick now to these lines of code.

    #!/usr/bin/python
    import sys
    import time
    while 1:
        time.sleep(0.01)
        for line in sys.stdin:
            pass # do something useful
    

    If i don't use time.sleep, the script will create a too high load on cpu usage.

    If i use:

    for line in sys.stdin.readline():
    

    It will only parse one line in 0.01 seconds and the performance of the apache2 is really bad Thank you very much for your answers.

    best regards Abalus

提交回复
热议问题