Thread-safety for accessing `_printer` and `_settings` in plugin?

Hi @foosel,

Sorry to tag you directly. This is the question probably only you can answer.

Are the variables such as _printer and _settings injected into plugins thread-safe? My plugin (OctoPrint Anywhere) has a few long-running threads that performs read operations such as:

  • self._printer.get_state_id()
  • self._settings.settings.effective['temperature']
  • self._printer.get_current_data()

The reason why I ask this question is that some users complained that my plugin cause crashes (apparently OctoPrint process quit, and/or even the OS died). But I went through every line of my code and the only remote possibility that my plugin could cause this kind of crash is some kind of thread-safety issue.

Your prompt response will be appreciated!

They should be. I use them all over the place.

If you can find someone to reliably reproduce the issue I'd ask them to run OctoPrint manually from command line in a screen, on OctoPi:

screen
sudo service octoprint stop
~/oprint/bin/octoprint serve

If OctoPrint crashes without any log entries that sounds like it might be crashing hard, as in the python process itself crashing, possibly segfaulting. It might be interesting to see what output to stdout that potentially produces.

Thanks @foosel. Yes I have had the habit of running OctoPrint using screen so that I could catch some crashes but have not had any myself... :frowning: It doesn't sound anyone has caught anything significant either.