cStringIO, leyendo bytes en fragmentos hasta EOF?
Frecuentes
Visto 167 veces
0
I want to read a string in chunks of 1MB at a time, then upload it over XMLRPC, would this be the best way to do this? Is there anything I should watch out for?
while data.read(1048576) != None:
data.seek(1048576, 1)
if not rpc_srv.chunk_upload(tf_uuid, data_chunk):
raise Exception('Failed to upload data.')
1 Respuestas
1
Puede utilizar el iter()
función with a sentinel to simplify your loop:
for data_chunk in iter(lambda: data.read(1048576), ''):
if not rpc_srv.chunk_upload(tf_uuid, data_chunk):
raise Exception('Failed to upload data.')
No hay necesidad de .seek()
, la .read()
call already updates the position.
Respondido 24 ago 12, 10:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas python xml-rpc or haz tu propia pregunta.
after implementing this, i've started getting "Memory Error"'s - jharwood
@Jharwood: create a new question with a full traceback. It could be a totally unrelated problem somewhere else, or it could be the size of your cStringIO instances, for example. - Martijn Pieters