I'm reading a constant flow of data over a serial port, using pyserial:
import serial
s = serial.Serial('/dev/ttyACM0', 9600)
If I'm using .read method, like this
while True:
print(s.read(1000))
It consumes something around 1-2% CPU
But if I start getting them in a list, which is more convenient, like that
while True:
print(s.readlines(1000))
CPU usage suddenly spikes up to 50%, which seems a bit unreasonable with only difference of output being split in the new lines.
Am I doing something wrong, is there a way to get readlines() method to use CPU more sparingly?
Thank you