rpi-ws281x / rpi-ws281x-python

Python library wrapping for the rpi-ws281x library
BSD 2-Clause "Simplified" License
319 stars 102 forks source link

Segmentation fault when trying to end the the program #49

Closed cp2004 closed 4 years ago

cp2004 commented 4 years ago

Hi there!

I am trying to create an OctoPrint plugin that displays the status of the 3D Printer using a strip of LEDs. To give you some details on how it's working:

  1. After startup, a thread is created as an 'effect runner', it's job is to start the strip (strip = rpi_ws281x.PixelStrip and strip.begin) and then just loop over the effect named by a queue, to communicate current printing state etc.
  2. Whenever the user changes settings, this thread is stopped and restarted with the new settings. This bit works
  3. When the user wants to end the server, OctoPrint calls an on_shutdown event, which my plugin is supposed to react to and end the thread in the same way it does on settings change. However, looking through the deugger it never gets this far.

When I stop the server, I am immediately presented with a Segmentation fault from somewhere within this library. My implementation works when I create a FakeStrip instead of a PixelStrip (Class I made to test the strip, does nothing). Running the library using threads (Outside OctoPrint) and handling a KeyboardInterupt works too.

I have come a long way down this road, so my question is really, is there anything that goes on behind the scenes so that this library also reacts to the signal to end?

Any help, insight, examples of other implementations, or really anything would be really appreciated. Thanks!

Edit: This happens on any version I try going back to 4.2, as I'm on a Pi4

Edit2: For more details, I'm running it over SPI as OctoPrint shouldn't be run as root

cp2004 commented 4 years ago

Update on this issue: Have since switched to multiprocessing and this no longer happens.