Пример #1
0
 def run(self, file, request, threadpool, chunk_size=constants.DEFAULT_CHUNK_SIZE, send_ahead=constants.SEND_AHEAD):
     self.watch(request)
     seek_ptr = 0
     chunks_sent = 0
     other_received = 0
     with open(file, 'rb') as f:
         while True:
             chunk = read_file_async(threadpool, f, limit=chunk_size)
             more_coming = len(chunk) > 0
             request << ('chunk', chunk, more_coming, chunks_sent)
             seek_ptr += len(chunk)
             chunks_sent += 1
             if not more_coming:
                 break
             try:
                 timeout = (0 if seek_ptr - other_received < send_ahead else None)
                 msg = self.get(OR(('terminated', request), ('received', ANY)), timeout=timeout)
             except Empty:
                 continue
             if msg == ('received', ANY):
                 _, other_received = msg
             else:
                 break
     while True:
         msg = self.get(OR(('received', ANY), ('terminated', request)), timeout=10.0)
         if msg[0] == 'terminated':
             break
Пример #2
0
    def run(self, service, pub_id, file, send_to):
        self.watch(send_to)

        seek_ptr = 0

        while True:
            try:
                msg = yield with_timeout(OPEN_FILE_TIMEOUT, self.get())
            except Timeout:
                err("Sending of file at %r timed out" % (file,))
                break

            if ('next-chunk', ANY) == msg:
                service << ('touch-file', pub_id)
                _, chunk_size = msg

                chunk = yield read_file_async(file, start=seek_ptr, end=seek_ptr + chunk_size)
                seek_ptr += len(chunk)

                more_coming = len(chunk) == chunk_size

                send_to << ('chunk', chunk, more_coming)

                if not more_coming:
                    break

            elif ('terminated', send_to) == msg:
                break

            else:
                self.unhandled(msg)
Пример #3
0
 def run(self,
         file,
         request,
         threadpool,
         chunk_size=constants.DEFAULT_CHUNK_SIZE,
         send_ahead=constants.SEND_AHEAD):
     self.watch(request)
     seek_ptr = 0
     chunks_sent = 0
     other_received = 0
     with open(file, 'rb') as f:
         while True:
             chunk = read_file_async(threadpool, f, limit=chunk_size)
             more_coming = len(chunk) > 0
             request << ('chunk', chunk, more_coming, chunks_sent)
             seek_ptr += len(chunk)
             chunks_sent += 1
             if not more_coming:
                 break
             try:
                 timeout = (0 if seek_ptr - other_received < send_ahead else
                            None)
                 msg = self.get(OR(('terminated', request),
                                   ('received', ANY)),
                                timeout=timeout)
             except Empty:
                 continue
             if msg == ('received', ANY):
                 _, other_received = msg
             else:
                 break
     while True:
         msg = self.get(OR(('received', ANY), ('terminated', request)),
                        timeout=10.0)
         if msg[0] == 'terminated':
             break