ulimit on open sockets ?
Alex Martelli
aleax at mac.com
Thu Apr 12 23:15:05 EDT 2007
On Apr 12, 2007, at 1:17 PM, Maxim Veksler wrote:
...
> Now, someone I work with suggested a simple work around "Pass the list
> objects in groups of 1024 each time to the select.select structure". I
> think it's acceptable and good advice, the thing is I don't know how
> to implement this "the python way" (that is - with out it being ugly).
I don't understand how you're going to make it work (I see no select
calls in your code and I don't understand how you'd get one in there
by polling), but I'm going to just explain how to get slices of 1024
items at a time from a long list.
Simplest way:
for i in xrange(0, len(longlist), 1024):
shortlist = longlist[i:i+1024]
# rest of the body goes here
More elegant/reusable:
def sliceby(longlist, N=1024):
for i in xrange(0, len(longlist), 1024):
yield longlist[i:i+1024]
for shortlist in sliceby(longlist):
# body goes here
If you want to show off, itertools.groupby may be suitable for that:
for _, g in itertools.groupby(enumerate(longlist), lambda (i, j): i//
1024):
shortlist = list(a for b, a in g)
# rest of the body goes here
but I wouldn't recommend it in this case for other purposes.
Alex
More information about the Python-list
mailing list