无法打开设备:打开的文件太多错误
Posted
技术标签:
【中文标题】无法打开设备:打开的文件太多错误【英文标题】:can't open device: Too many open files Error 【发布时间】:2017-10-24 07:54:20 【问题描述】:嗨,我在 Raspberry Pi 3 中有糟糕的代码。我正在尝试阅读 4 RC522 模块,我可以做到。但几分钟后,我得到“无法打开设备:打开的文件太多”错误,我的 while 循环终止了。
我没有共享所有功能。我想重要的部分是while循环。我在每个循环中创建实例。我想这是一个很大的错误。我不能添加延迟。我尝试将 null 分配给我的对象,但我仍然遇到同样的错误。我的代码在下面
注意:我有 4 个 SPI 地址,我用它们创建实例。
#!/usr/bin/env python
# -*- coding: utf8 -*-
import time
import sys
import os
import RPi.GPIO as GPIO
import MFRC522
import signal
from time import gmtime, strftime
from time import sleep
import requests
#import xml.etree.ElementTree as ET
#import xmltodict, json
from lxml import objectify
from bs4 import BeautifulSoup
continue_reading = True
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
GPIO.setup(37, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
continue_reading = False
GPIO.cleanup()
kullanici = "xxxx"
sifre = "xxxx"
birim = "xxxx"
ogrKEY = " "
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
continue_reading = False
GPIO.cleanup()
# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)
# Create an object of the class MFRC522
#
adresler = ["/dev/spidev0.0", "/dev/spidev0.1", "/dev/spidev1.0","/dev/spidev1.1"]
# Welcome message
print "Welcome to the MFRC522 data read example"
print "Press Ctrl-C to stop."
j = 0
# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:
MIFAREReader = None
pin = 0
if j == 100:
j = 0
i = j % 4
if i == 0:
MIFAREReader = MFRC522.MFRC522(adresler[0], 16)
pin = 15
elif i == 1:
MIFAREReader = MFRC522.MFRC522(adresler[1], 18)
pin = 13
elif i == 2:
MIFAREReader = MFRC522.MFRC522(adresler[2], 33)
pin = 7
else:
MIFAREReader = MFRC522.MFRC522(adresler[3], 31)
pin = 37
# Scan for cards
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
# If a card is found
if status == MIFAREReader.MI_OK:
print "Card detected"
# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
# If we have the UID, continue
if status == MIFAREReader.MI_OK:
# print "su okuyucudan okundu" % i
# Print UID
print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])
# This is the default key for authentication
key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
# Select the scanned tag
MIFAREReader.MFRC522_SelectTag(uid)
# Authenticate
status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 10, key, uid)
# Check if authenticated
if status == MIFAREReader.MI_OK:
MIFAREReader.MFRC522_Read(10)
ogrKEY = MIFAREReader.returnOGR()
sonuc = parser(ogrKEY)
if sonuc == True:
openTurnsTile(pin)
else:
sonuc = personelKontrol(ogrKey)
if sonuc == True:
openTurnsTile(pin)
MIFAREReader.MFRC522_StopCrypto1()
else:
print "Authentication error"
j = j + 1
【问题讨论】:
【参考方案1】:当您创建 MFRC522 对象时,它实际上调用了spi.openSPI()
,但从不关闭它。这个 python 库适用于单实例,但现在您正在处理打开 FD 的多个实例,也需要使用 spi.closeSPI()
关闭,否则您将收到错误“打开的 FD 太多”。
检查您的 PID 中有多少 open FDs。
【讨论】:
没有closeSPI函数:( 对不起,我找到了,closeSPI 函数自然在 spi 库中,很抱歉 :) 谢谢。 如果这有帮助,你能放弃投票吗?谢谢:)以上是关于无法打开设备:打开的文件太多错误的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio 无法在 OpenSUSE 上启动(打开的文件太多)
Qt 上的“GLib-ERROR **:无法创建管道主循环唤醒:打开的文件太多”
无法打开链接描述文件 libgcc_s.so.1:打开的文件太多
信息:无法打开物理文件“路径”。操作错误5:“5(拒绝访问。)”(MICROSOFT SQL Server,错误:5120)