Ah, yes. There are, in my case. (why do I always seem to be doing stuff that
is different from what you all are doing:)
The particular piece of code is from the chunked reader. It may be reading
rather large chunks at a time (several lots of Kb.):
def recvchunk(socket):
len = socket.unpack('i', recv_exactly(socket, 4))
return recv_exactly(len)
#old style
def recv_exactly(socket, length):
data = []
while length:
got = socket.receive(length)
if not got: raise EOFError
data.append(got)
length -= len(got)
return "".join(data)
#new style
def recv_exactly(socket, length):
data = bytearray(length)
view = memoryview(data)
while length:
got = socket.receive_into(view[-length:])
if not got: raise EOFError
length -= len(got)
return data
Here I spot another optimzation oppertunity: let memoryview[:] return self,
since the object is immutable, I believe.
K
> -----Original Message-----
> From: "Martin v. Löwis" [mailto:[email protected]]
> Sent: 1. nóvember 2010 14:22
> To: Kristján Valur Jónsson
> Cc: [email protected]
> Subject: Re: [Python-Dev] new buffer in python2.7
>
>
> Assuming there are multiple recv calls. For a typical struct, all data
> will come out of the stream with a single recv. so no join will be
> necessary.
>
> Regards,
> Martin
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com