gpt4 book ai didi

python - __init__ OSError : [Errno 24] Too many open files中的 “/usr/lib/python3.5/socket.py”文件,第134行

转载 作者:行者123 更新时间:2023-12-03 12:08:23 33 4
gpt4 key购买 nike

我在树莓派Pi3的while循环中调用广播和接收数据功能。在while循环之后,我想调用另一个函数,该函数会将帧发送到他的邻居节点,但是当此函数(send_req_status_frame())调用时,它给出了一个错误

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

它在“send_req-status-frame”功能的“s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)”行上给出错误。
有人可以帮我解决这个错误吗?
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()
临时=并发。 future 。线程池执行器(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()

最佳答案

如果您使用的是Mac OS或Linux变体,则可以查看打开文件的限制,然后增加该值。

# 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

要增加限制(在RPI3上最大为65536,在Mac OSX上最大为18432):
# ulimit -Sn 5000

关于python - __init__ OSError : [Errno 24] Too many open files中的 “/usr/lib/python3.5/socket.py”文件,第134行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51365111/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com