【问题标题】:File "/usr/lib/python3.5/socket.py", line 134, in __init__ OSError: [Errno 24] Too many open files__init__ OSError 中的文件“/usr/lib/python3.5/socket.py”第 134 行:[Errno 24] 打开的文件太多
【发布时间】:2018-07-16 15:18:16
【问题描述】:

我在树莓派 3 的 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() 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()

【问题讨论】:

    标签: python python-3.x sockets raspberry-pi3 serversocket


    【解决方案1】:

    如果您使用的是 Mac OS 或 Linux 版本,您可以查看打开文件的 ulimit,然后增加该值。

    # 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
    

    【讨论】:

    • @ode2k 我正在使用树莓派3
    • 它也应该适用于 PI3。我会更新答案。
    • 我在 'limits.conf' 文件中添加了这些行,但得到了同样的错误。
    • @ode2k 你能告诉我这些线的位置在哪里吗?我看到“limits.conf”,但在这个文件中“ulimit -a”行不包含。那么我应该在哪个位置修改限制呢?
    • 您需要运行命令 ulimit -Sn &lt;**limit size**&gt; 将其设置为值 ulimit -Sn 65536 然后运行 ​​ulimit -a 以查看更改。
    猜你喜欢
    • 2020-03-07
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多