python - How to delete files "slowly"?
阿神
阿神 2017-05-16 13:31:15
0
1
643

Now there is a requirement to delete slow cache files in the background. The cache files are very large. Sometimes a single file is hundreds of gigabytes. When deleting, the hard disk usage must not exceed 5%~10%. Is there any way?

win7 NTFS partition

In fact, you can also ask, how to delete part of the file instead of the entire file? It seems that I can't escape the IO of reading? Can I directly erase the contents of a file?

阿神
阿神

闭关修行中......

reply all(1)
给我你的怀抱

Written a github. Welcome to help test: github link

I tried using truncate. It can control the deletion speed and content, but I didn’t do a detailed test. I only looked at the performance manager of win. Didn't see it being fully loaded.


# frw = open(filename, "wb")
# for a in xrange(10):
#     frw.write('rrreee'*1024*1024*1024)
# frw.close()
#
# assert  1== 2

import os
import time

while True:

    time.sleep(0.01)

    SIZE = os.path.getsize(filename)

    print SIZE

    frw = open(filename, "r+b")
    frw.seek(SIZE-1024*1024, 0)

    frw.truncate()
    frw.close()
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template