Skip to content

Fix "OSError: [Errno 9] Bad file descriptor" for Waveshare EPDs - #728

Open
motschel123 wants to merge 2 commits into
fatihak:mainfrom
motschel123:main
Open

Fix "OSError: [Errno 9] Bad file descriptor" for Waveshare EPDs#728
motschel123 wants to merge 2 commits into
fatihak:mainfrom
motschel123:main

Conversation

@motschel123

Copy link
Copy Markdown

Waveshare EPDs fully close the SPI file descriptor when being put to sleep.
This result in OSError: [Errno 9] Bad file descriptor when diplay_image is called a second time. See #452, #259.

It can be discussed whether this is a bug in the waveshare drivers or intended behavior. However the fix proposed in #259 has been an open PR (waveshareteam/e-Paper#406) for half a year now without any reactions, so it can be assumed to not get fixed.

So heres the fix for this implementation:
The epd_module.EPD() constructor has to be called again for each display_image step.
For this i implemented a small reinitialize_display function for the waveshare_display which recreates the epd_display each time display_image is called.
To safe resources I made the dynamic module import an Object field to be reusable.

I can confirm this code to work for the epd13in3k model and this model alone, as it's the only one I own.
But when looking into the waveshare epd drivers, the relevant piece of code is present for every model.

Copilot AI review requested due to automatic review settings July 17, 2026 20:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent OSError: [Errno 9] Bad file descriptor when updating Waveshare EPDs multiple times by reinitializing the EPD/SPI setup after the display is put to sleep (since some Waveshare drivers close the SPI FD during sleep()).

Changes:

  • Persist the dynamically imported Waveshare EPD module on the WaveshareDisplay instance for reuse.
  • Add a reinitialize_display() helper intended to recreate the EPD() instance and run its init method again.
  • Document the rationale for reinitialization in-code.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/display/waveshare_display.py
Comment thread src/display/waveshare_display.py
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

Successfully merging this pull request may close these issues.

2 participants