sábado, 22 de setembro de 2018

Pra que serve flush na comunicação serial

"The data is held in a memory buffer because memory is faster than disk i/o. Your data would be written to the file once you close the file, but I guess you want to read it wile you're writing it? To do that, the f.flush() suggested by @Gerard will cause the memory buffer to be written to your file; or at least to the system's disk cache if it's using one. You may also wish to consider adding an os.fsync(f) following the f.flush. This will ensure that the system's disk cache is also written to the file, and avoid data loss in the event of an "unexpected event".
As a general practice, I think I would avoid using a zero-sized buffer for your file. That would defeat the purpose of using memory buffers, which is to keep things moving briskly forward. But feel free to try it - the performance reduction may be irrelevant, depending upon your application: f=open("myFile.txt","w+",0)"