问题
I've read somewhere that the use of flush is necessary to reduce lag. Is this true?
I'm not really sure about using it. Please help me understand what it does exactly.
I've checked pyserial docs but it didnt give me much information. All it said was:
flush() Flush of file like objects. It’s a no-op in this class, may be overridden.
回答1:
Information you're sending/writing may be temporarily stored in a buffer, so that a larger chunk can be written in one go. So, if you do:
f = open("test.txt","w")
f.write("Hello")
test.txt will still be empty, until you do f.flush()
to flush the buffer. f.close()
also flushes the buffer before closing the file.
The document you've got says that it's a "no-op" - a no-operation, meaning that if you're actually using that class, it doesn't do anything. If you're using a subclass, it might do something.
来源:https://stackoverflow.com/questions/5116780/using-pyserial-flush-method