Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOError: [Errno 24] Too many open files #31

Closed
codylallen opened this issue Oct 6, 2015 · 4 comments
Closed

IOError: [Errno 24] Too many open files #31

codylallen opened this issue Oct 6, 2015 · 4 comments

Comments

@codylallen
Copy link

When implemented for a large stream of data to send, the script crashes with "IOError: [Errno 24] Too many open files".

Method of implementation is:
def SendSong(bytes):
speed = 2500000
print("Sending packets . . . ")
while(len(bytes) > 0):
if(len(bytes) > 4096):
SPI_sendPackets(bytes[:4096], speed)
bytes_read = bytes[4097:]
else:
SPI_sendPackets(bytes_read, speed)
bytes_read = list()

def SPI_sendPackets(listOfPackets, speed):
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz = speed

spi.xfer2(listOfPackets)
@doceme
Copy link
Owner

doceme commented Oct 6, 2015

The problem is you are calling open from within SPI_sendPackets and not closing it. Doing this many times over and over gives you the error message you are seeing, "Too many open files."

You shouldn't be opening and closing spidev for every transfer. Just create a spi object somewhere toward the beginning of your code and only call open on it once. Then just pass the spi object to SPI_sendPackets and you should be fine.

It looks like you have one other error in your code. bytes[:4096] will give you bytes 0-4095 (the first 4096 bytes), but bytes[4097:] will skip byte 4096 and give you bytes 4097 to the end of the list. I'm not sure you meant to skip that byte.

@doceme doceme closed this as completed Oct 6, 2015
@codylallen
Copy link
Author

Hello,

Thank you for your fast response and assistance. I am embarrassed I made such an amateur mistake!

Have a great day.

Cheers,
Cody

////////////////////////////////////////////
Cody L. Allen
Purdue University
College of Engineering
ECESS Vice President
Mobile: 765.299.2447
////////////////////////////////////////////

Sent from my iPhone

On Oct 6, 2015, at 4:42 PM, doceme notifications@github.com wrote:

The problem is you are calling open from within SPI_sendPackets and not closing it. Doing this many times over and over gives you the error message you are seeing, "Too many open files."

You shouldn't be opening and closing spidev for every transfer. Just create a spi object somewhere toward the beginning of your code and only call open on it once. Then just pass the spi object to SPI_sendPackets and you should be fine.

It looks like you have one other error in your code. bytes[:4096] will give you bytes 0-4095 (the first 4096 bytes), but bytes[4097:] will skip byte 4096 and give you bytes 4097 to the end of the list. I'm not sure you meant to skip that byte.


Reply to this email directly or view it on GitHub.

@doceme
Copy link
Owner

doceme commented Oct 6, 2015

No problem. Happy to help. I'm sure I've done worse many times. That's why I love open source.

mrwunderbar666 added a commit to mrwunderbar666/Python-RPi-MCP4922 that referenced this issue Aug 22, 2017
opening spidevice with each command wasn't a good idea:
see: doceme/py-spidev#31
@rajdpandey
Copy link

The problem is you are calling open from within SPI_sendPackets and not closing it. Doing this many times over and over gives you the error message you are seeing, "Too many open files."

You shouldn't be opening and closing spidev for every transfer. Just create a spi object somewhere toward the beginning of your code and only call open on it once. Then just pass the spi object to SPI_sendPackets and you should be fine.

It looks like you have one other error in your code. bytes[:4096] will give you bytes 0-4095 (the first 4096 bytes), but bytes[4097:] will skip byte 4096 and give you bytes 4097 to the end of the list. I'm not sure you meant to skip that byte.

Sir, I am Getting Same Issue But With MFRC522 Library Which Uses Spidev. And I am Not been able to solve This.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants