I am calling broadcasting and receiving data function in while loop on raspberry Pi3. After the while loop, i want to call the other function, which will send the frame to his neighbor nodes, but when this function (send_req_status_frame()) calls, it gives an error
Traceback (most recent call last):
File "Neighbortest.py", line 347, in <module>
File "Neighbortest.py", line 286, in send_req_status_frame
File "/usr/lib/python3.5/socket.py", line 134, in __init__
OSError: [Errno 24] Too many open files
It give error on "s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)" line of "send_req-status-frame" function. Can anybody help me how I can fix this error?
def send_req_status_frame():
message='req_status'
previous_ip=My_ip
sender_ip=My_ip
T_message= message + ";" + previous_ip + ";" + sender_ip
T_message_bytes= bytes(T_message,'utf-8')
print ("----Send_req_status_frame: Send to My_Neighborlist",MyNeighborSet_ip)
PORT = 12345
print ("just after socket")
for i in range (len(MyNeighborSet_ip)):
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.connect((MyNeighborSet_ip[i],PORT))
s.sendall (T_message_bytes) #here is issue of 'byte'
s.close()
start_time=time.time() temp = concurrent.futures.ThreadPoolExecutor (max_workers=2)
while(((time.time()-start_time)<NeighborDiscovery_Time_Interval) and (len(MyNeighborSet_ip) <= Nmax_Per_hop)):
if (time.time()-start_time<hello_Broadcast_Period):
broadcast_hello()
try:
temp.submit(received_hello)
except:
print("###################")
send_req_status_frame()
If you are using Mac OS or Linux variant, you can view the ulimit of open files, then increase the value.
# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 256
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 1064
virtual memory (kbytes, -v) unlimited
To increase the limit (up to 65536 on RPI3, 18432 on Mac OSX):
# ulimit -Sn 5000
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.