I'm successfully reading data from my NFC tags with the py532lib, using the i2c connection, put out by Hubcitylabs 5 years ago. https://github.com/HubCityLabs/py532lib/blob/master/py532lib/i2c.py

Unfortunately, after running for about 15 minutes, the system crashes with the error:

OSError: Error 24 Too Many Open Files: '/dev/i2c-1'

Here's the portion of code I have written, that's using the library. Anyone have an idea what I need to add in order to actually close out the files? I've done some reading and it sounds like it's leaving open file descriptors (maybe?).

def nfc_list(self):
    uid = Mifare().scan_field()
    if uid:
        """Grab the entire output of the NFC mobule from the I2C channel."""
        self.nfc_read = Pn532_i2c().read_mifare().get_data() #Store it in our variable.
        #print('nfc_read = ' + str(self.nfc_read))
        self.nfc_read = '' #empty out the array
        #print('no tag found')

This thing has been sitting to the side on my desk for a few months now because I just got tired of getting nowhere with it. Any help is greatly appreciated.

  • 1
    are you writing the data to a file in code you haven't shown perhaps? Jan 25, 2019 at 2:47
  • I'm only reading the tag and using it stored in the variable, nfc_read. My guess is there's a memory leak in that i2c library, linked above, that isn't automatically closing out files that it creates. I manually added the reset_i2c() and bus.close() commands in an attempt to handle this, but it doesn't seem to be working.
    – Bobby Hill
    Jan 25, 2019 at 13:51
  • Can someone possibly point me to where this file location is? Maybe I can crudely just delete everything in there on every call.
    – Bobby Hill
    Feb 9, 2019 at 19:22

1 Answer 1


I had the same problem with the mfrc522 library.

I also tried to close the bus from my own code (like you) but it didn't work out.

So I decided to read the source code and I saw the 'Close' function which closes opened bus (Basically the code was able to close that bus from inside) and then I added that function to the end of the reading function, then everything was working just fine.

So you can try to look for the close function or make your own in the source code of the library.

  • Are you talking about the reset_i2c(self) function here? It contains the self.PN532.close(). It looks like it calls the close() function, here, but I've had that in my code and it didn't help. I guess you mean trying to call that close() function directly myself. If only I could understand how to dig that deep. lol
    – Bobby Hill
    Jul 31, 2019 at 0:04
  • *Sorry for all the edits, I'm used to Reddit. I just realized what my mistake is, I only imported the py532lib, and left out the quick2wire portion... I did this according to the author's notes. Wait, no, I'm dumb. The Pn532lib section imports the quick2wire bits. So, what I did should definitely be working.
    – Bobby Hill
    Jul 31, 2019 at 0:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.