Abort a slow flush to disk after write?
Posted
by Therealstubot
on Stack Overflow
See other posts from Stack Overflow
or by Therealstubot
Published on 2010-03-16T22:30:18Z
Indexed on
2010/03/16
22:41 UTC
Read the original article
Hit count: 339
Is there a way to abort a python write operation in such a way that the OS doesn't feel it's necessary to flush the unwritten data to the disc?
I'm writing data to a USB device, typically many megabytes. I'm using 4096 bytes as my block size on the write, but it appears that Linux caches up a bunch of data early on, and write it out to the USB device slowly. If at some point during the write, my user decides to cancel, I want the app to just stop writing immediately. I can see that there's a delay between when the data stops flowing from the application, and the USB activity light stops blinking. Several seconds, up to about 10 seconds typically. I find that the app is holding in the close() method, I'm assuming, waiting for the OS to finish writing the buffered data. I call flush() after every write, but that doesn't appear to have any impact on the delay. I've scoured the python docs for an answer but have found nothing.
© Stack Overflow or respective owner