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 the manpage from python, i use the following code but it totally overloads my cpu.
#!/usr/bin/python -u
import sys
while 1:
for line in sys.stdin.readlines():
do something useful
Is there any good way to solve the high cpu usage?
Edit:
All your solutions don't work. I give you exactly my problem.
You can configure the apache2 daemon that he sends every logline to a program and not to write in a logfile.
This looks something like that:
CustomLog "|/usr/bin/python -u /usr/local/bin/client.py" combined
Apache2 expects from my script that it runs always, waits for data on sys.stdin and parses it then there is data.
If i only use a for loop the script will exit, because at a point there is no data in sys.stdin and apache2 will say ohh your script exited unexpectedly.
If i use a while true loop my script will use 100% cpu usage.