doceme / py-spidev

MIT License
461 stars 203 forks source link

after close and recreate got Bad file decriptor #115

Closed wiryonolau closed 3 years ago

wiryonolau commented 3 years ago

Hi what is the clean way to close and reuse spidev

I close the board then try recreate and got this error when recreate ( program still running )

spi.close()

spi = spidev.SpiDev()

# when calling
spi.xfer([REG.LORA.OP_MODE | 0x80, 128])
<class 'OSError'>, OSError(9, 'Bad file descriptor') 

We use the pySX127x Lora library
REG.LORA_OP_MODE is 0x01

wiryonolau commented 3 years ago

Found the problem , closing this issue

I run in a GUI Application using pygobject which has start and stop button to read from spi If I do spi.close() on stop event, the next start event will have bad file descriptor error. I can only do spi.close() when the application is closing

It's looks like the application is still holding the file when you do spi.close() if it still running.