[Twisted-Python] deferreds and unpacking binary data

Xtroce xtroce at gmail.com
Mon May 10 11:01:44 MDT 2010


Question: A Protocol should unpack some binary data. this is done in
seperate calls to struct.unpack . Inbetween i do some checks for
length, some strings returned are concatenated using join and logs are
written. This all happens in the factory of the Protocol. To keep the
code unblocking would it be wiser to spawn new Threads from the
Protocol around the whole function, like:
d = threads.deferToThread(self.factory.readPackage, data)
 because it all has to happen after one another anyway.
Or should i split it up in deferreds which if i get it correctly would
mean to create callback functions for each of the unpack()'s, join()'s
and str()'s
thanks




More information about the Twisted-Python mailing list