[Twisted-Python] synchronous problem
Wu Zhe
jessewoo at gmail.com
Tue Jul 8 06:07:43 MDT 2008
Hi
I have a series of files to transfer, each followed by a line sent to
specify the file size and crc number. As we can see here I need
synchronous behavior, only after the previous file transfer complete,
can the for loop step into the next iteration to send the next file
via sender.beginFileTransfer. How can i achieve this? Here is the
problematic code:
def import_query(self, path_list):
number_of_files = len(path_list)
line = '3#%s' % number_of_files
self.client_instance.sendLine(line)
sender = FileSender()
sender.CHUNK_SIZE = common.chunk_size
for path in path_list:
f = open(path, 'rb')
s = f.read()
filesize = len(s)
crc = crc32(s)
line = '3#%s:%s' % (filesize, crc)
self.client_instance.sendLine(line)
def transfer_completed(lastsent):
f.close()
self.client_instance.setLineMode()
# send the file
self.setRawMode()
d = sender.beginFileTransfer(f, self.client_instance.transport)
d.addCallback(transfer_completed)
--
Wu Zhe
Best Regards
More information about the Twisted-Python
mailing list