help on file storage for split multi part download
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Mar 7 04:14:35 EST 2008
En Fri, 07 Mar 2008 04:16:42 -0200, <coolman.guron at gmail.com> escribi�:
> On Mar 7, 1:38 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
>> En Thu, 06 Mar 2008 14:34:27 -0200, <coolman.gu... at gmail.com> escribi�:
>>
>> > storage class which can write the file splits that are currently being
>> > downloaded to the disk. this is exactly what other download
>> > accelerators do, i guess.
>>
>> Uh, unless I misundersand you, a standard file object is enough. First
>> create a file with the required size (open(...,'wb'), seek(n-1),
>> write(chr(0))). For each downloaded chunk you have to know its position
>> in
>> the file; then just seek() and write() it.
>
> BUT the thing thats going in my mind is thread safety. i plan to start
> each part of the file download in a different thread. and then when
> each thread had downloaded more than 100kb (or eof or boundary
> reached) write the buffer to the disk. can this be achieved using
> mutex ? i have never shared objects between threads.
Use a different (single) thread to write the file; the others put write
requests on a Queue.queue object, and the writer just gets the requests
and processes them.
> is there a way to write this without using threads at all ???
Using asyncore, and perhaps the Twisted framework.
--
Gabriel Genellina
More information about the Python-list
mailing list