Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在某处读到,使用刷新对于减少延迟是必要的。这是真的?
我不太确定使用它。请帮助我了解它的确切作用。
我检查了 pyserial 文档,但没有给我太多信息。它只说:
flush() 文件类对象的刷新。这是此类中的空操作,可能会被覆盖。
您正在发送/写入的信息可能会暂时存储在缓冲区中,以便一次写入更大的块。所以,如果你这样做:
f = open("test.txt","w") f.write("Hello")
test.txt 仍然是空的,直到你f.flush()刷新缓冲区。f.close()在关闭文件之前也会刷新缓冲区。
f.flush()
f.close()
你得到的文件说它是一个“无操作” - 一个无操作,这意味着如果你实际使用该类,它不会做任何事情。如果您使用的是子类,它可能会做一些事情。