ulimit on open sockets ?

Maxim Veksler hq4ever at gmail.com
Sat Apr 14 07:02:05 EDT 2007


On 4/13/07, Alex Martelli <aleax at mac.com> wrote:
>
> 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.
>

Thank you. I'm attaching the full code so far for reference, sadly it
still doesn't work. It seems that select.select gets it's count of
fd's not from the amount passed to it by the sub_list but from the
kernel (or whatever) count for the process; The main issue here is
that it seems I won't be able to use select for the simple
non-blocking process and am forced to check poll to see if that helps.

The error I'm getting is still the same:

# ulimit -n
500000
# python listener_sockets_range.py
Traceback (most recent call last):
  File "listener_sockets_range.py", line 22, in ?
    ready_to_read, ready_to_write, in_error =
select.select(select_cap_sockets, [], [], 0)
ValueError: filedescriptor out of range in select()


"""
#!/usr/bin/env python

import socket, select

def get_non_blocking_socket(port_number):
    print port_number

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setblocking(0)
    s.bind(('0.0.0.0', port_number))
    s.listen(1)
    return s

def slice_by_fd_limit(longlist, N=1024):
    for i in xrange(0, len(longlist), N):
        yield longlist[i:i+N]

all_sockets = map(get_non_blocking_socket, xrange(10000, 20000))

while 1:
    for select_cap_sockets in slice_by_fd_limit(all_sockets):
        ready_to_read, ready_to_write, in_error =
select.select(select_cap_sockets, [], [], 0)
        for nb_active_socket in all_sockets:
            if nb_active_socket in ready_to_read:
                conn, addr = nb_active_socket.accept()
                while 1:
                    data = conn.recv(1024)
                    if not data: break
                    conn.send(data)
                conn.close()
"""

-- 
Cheers,
Maxim Veksler

"Free as in Freedom" - Do u GNU ?



More information about the Python-list mailing list