bz2 & cpu usage

Brad Tilley bradtilley at gmail.com
Tue Oct 19 09:51:39 EDT 2004


I'd like to keep at least 50% of the cpu free while doing bz2 file 
compression. Currently, bz2 compression takes between 80 & 100 percent 
of the cpu and the Windows GUI becomes almost useless. How can I lower 
the strain on the cpu and still do compression? I'm willing for the 
compression process to take longer.

Thanks,

Brad

def compress_file(filename):
     path = r"C:\repository_backup"
     print path
     for root, dirs, files in os.walk(path):
         for f in files:
             if f == filename:
                 print "Compressing", f
                 x = file(os.path.join(root, f), 'rb')
                 os.chdir(path)
                 y = bz2.BZ2File(f + ".bz2", 'w')
                 while True:
                     data = x.read(1024000)
                     time.sleep(0.1)
                     if not data:
                         break
                     y.write(data)
                     time.sleep(0.1)
                 y.close()
                 x.close()
             else:
                 return



More information about the Python-list mailing list