3

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.

Artem Zankovich
  • 2,319
  • 20
  • 36
user571099
  • 1,491
  • 6
  • 24
  • 42

1 Answers1

3

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.

Thomas K
  • 39,200
  • 7
  • 84
  • 86
  • following your example should i immediately use f.flush after f.write("hello")? and im sorry i was confused with your comment regarding "if youre actually using that class, it doesnt do anything". please elaborate sir – user571099 Feb 25 '11 at 13:12
  • @user571099: The flush method on the class you're reading the documentation for does nothing. If you're using a subclass, it might have an effect. I suggest you try it, and see if it makes a difference. – Thomas K Feb 25 '11 at 13:26