ulimit on open sockets ?
Maxim Veksler
hq4ever at gmail.com
Mon Apr 9 19:23:27 EDT 2007
Hi,
I've written this code, the general idea was to listen on all 65535
port of tcp for connection.
"""
#!/usr/bin/env python
import socket, select
def get_non_blocking_socket(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
all_sockets = map(get_non_blocking_socket, xrange(10000, 15000))
while 1:
ready_to_read, ready_to_write, in_error =
select.select(all_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()
"""
The thing is that when I tried to run this at first I got
"""
python non_blocking_range.py
Traceback (most recent call last):
File "non_blocking_range.py", line 12, in ?
all_sockets = map(get_non_blocking_socket, xrange(10000, 15000))
File "non_blocking_range.py", line 6, in get_non_blocking_socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
File "/usr/lib/python2.4/socket.py", line 148, in __init__
_sock = _realsocket(family, type, proto)
socket.error: (24, 'Too many open files')
"""
So I set ulimit -n 500000, now I'm getting
"""
python non_blocking_range.py
Traceback (most recent call last):
File "non_blocking_range.py", line 15, in ?
ready_to_read, ready_to_write, in_error =
select.select(all_sockets, [], [], 0)
ValueError: filedescriptor out of range in select()
"""
Should I be using a different version of select or something? Or
should I implement this the other way around, if so please suggest
how.
Thank you very much,
(enthusiastically learning python) Maxim.
--
Cheers,
Maxim Veksler
"Free as in Freedom" - Do u GNU ?
More information about the Python-list
mailing list