import tarfile
from cStringIO import StringIO
from io import BytesIO as BIO
unique_keys = ['1:bigstringhere...:5'] * 5000
file_out = BytesIO()
tar = tarfile.open(mode='w:bz2', fileobj=file_out)
for k in unique_keys:
id, mydata, s_index= k.split(':')
inner_fname = '%s_%s.data' % (id, s_index)
info = tarfile.TarInfo(inner_fname)
info.size = len(mydata)
tar.addfile(info, StringIO(mydata))
tar.close()
我想执行上述循环以并行添加到 tarfile (tar) 以加快执行速度。
有任何想法吗?