Octoprint can't reconnect after printer is turned off then back on

What is the problem?

I've used octoprint for a number of years on a Raspberry PI 3 with an older printer without problem. I reflashed with SimplyPi when I got my new printer and while it works fine initially if I turn off the printer after I'm finished printing for the day, once I turn the printer back on OctoPrint cannot reconnect to the printer unless I restart the Raspberry Pi. I see in the logs it keeps saying stuff like "can't start new thread" but I can't tell from the logs what might be causing it.

What did you already try to solve it?

Rebooting Raspbery Pi seems to be only thing that solves the issue. Also unable to reboot OctoPrint or the Pi via menu command because of the "can't start new thread" error.

Have you tried running in safe mode?

No.

Did running in safe mode solve the problem?

Didn't try.

Systeminfo Bundle

octoprint-systeminfo-20220701211115.zip (937.8 KB)

Additional information about your setup

OctoPrint 1.8.1, SimplyPi 3.1.2, Ender 3 S1, Chrome, Windows 10

2022-07-01 20:17:31,301 - octoprint.plugins.action_command_notification - INFO - Notifications cleared
2022-07-01 20:17:31,438 - octoprint.plugins.SimplyPrint.comm - INFO - Connecting printer
2022-07-01 20:17:31,846 - octoprint.plugins.tracking - INFO - Sent tracking event commerror_autodetect, payload: {'commerror_text': 'No more candidates to test, and no working port/baudrate combination detected.'}
2022-07-01 20:17:31,871 - octoprint.plugins.SimplyPrint.comm - ERROR - can't start new thread
Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_simplyprint/comm/simplyprint.py", line 132, in main_loop
    request = self.request()
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_simplyprint/comm/simplyprint.py", line 504, in request
    self.process_demands(demand_list, response_json)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_simplyprint/comm/simplyprint.py", line 666, in process_demands
    self.printer.connect()
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/__init__.py", line 404, in wrapper
    return f(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/printer/standard.py", line 381, in connect
    self._comm.start()
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/comm.py", line 822, in start
    self.sending_thread.start()
  File "/home/pi/oprint/lib/python3.7/site-packages/sentry_sdk/integrations/threading.py", line 54, in sentry_start
    return old_start(self, *a, **kw)
  File "/usr/lib/python3.7/threading.py", line 847, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
2022-07-01 20:17:31,867 - octoprint.util.comm - INFO - Changing monitoring state from "Offline" to "Detecting serial connection"
2022-07-01 20:17:31,904 - octoprint.util.comm - INFO - Serial detection: Performing autodetection with 7 port/baudrate candidates: /dev/ttyUSB0@115200, /dev/ttyUSB0@250000, /dev/ttyUSB0@230400, /dev/ttyUSB0@57600, /dev/ttyUSB0@38400, /dev/ttyUSB0@19200, /dev/ttyUSB0@9600
2022-07-01 20:17:31,905 - octoprint.util.comm - INFO - Serial detection: Trying port /dev/ttyUSB0, baudrate 115200
2022-07-01 20:17:31,911 - octoprint.util.comm - INFO - Connecting to port /dev/ttyUSB0, baudrate 115200
2022-07-01 20:17:31,992 - octoprint.util.comm - INFO - Serial detection: Handshake attempt #1 with timeout 2.0s
2022-07-01 20:17:32,048 - octoprint.util.comm - ERROR - Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:
Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/comm.py", line 3100, in _monitor
    self._onConnected()
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/comm.py", line 3601, in _onConnected
    self._temperature_timer.start()
  File "/home/pi/oprint/lib/python3.7/site-packages/sentry_sdk/integrations/threading.py", line 54, in sentry_start
    return old_start(self, *a, **kw)
  File "/usr/lib/python3.7/threading.py", line 847, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
2022-07-01 20:17:32,139 - octoprint.util.comm - INFO - Changing monitoring state from "Detecting serial connection" to "Offline after error"
2022-07-01 20:17:32,167 - octoprint.access.users - INFO - Cleaning up user session 7C68565AEC7C4F8C97CE818892B07D86 for user _api
2022-07-01 20:17:32,170 - octoprint.access.users - INFO - Logged out user: _api
2022-07-01 20:17:32,171 - octoprint.access.users - INFO - Cleaning up user session 0E34EE782CCB4C099E45202160672B20 for user pougan
2022-07-01 20:17:32,172 - octoprint.server.util.sockjs - INFO - User pougan logged out, logging out on socket
2022-07-01 20:17:32,181 - octoprint.access.users - INFO - Logged out user: pougan
2022-07-01 20:17:32,182 - octoprint.access.users - INFO - Logged in user: pougan
2022-07-01 20:17:32,185 - octoprint.server.api - INFO - Actively logging in user pougan from ::ffff:192.168.50.138
2022-07-01 20:17:32,297 - octoprint.server.util.flask - INFO - Passively logging in user pougan from ::ffff:192.168.50.87
2022-07-01 20:17:32,299 - octoprint.access.users - INFO - Logged in user: pougan
2022-07-01 20:17:32,353 - octoprint.plugins.action_command_notification - INFO - Notifications cleared
2022-07-01 20:17:32,377 - octoprint.server.util.sockjs - INFO - User pougan logged in on the socket from client ::ffff:192.168.50.87
2022-07-01 20:17:32,418 - octoprint.server.util.flask - INFO - Passively logging in user pougan from ::ffff:192.168.50.138
2022-07-01 20:17:32,419 - octoprint.access.users - INFO - Logged in user: pougan
2022-07-01 20:17:32,868 - octoprint.plugins.tracking - INFO - Sent tracking event commerror_crash, payload: {'commerror_text': 'See octoprint.log for details'}
2022-07-01 20:17:32,899 - octoprint.server.util.sockjs - INFO - Client connection closed: ::ffff:192.168.50.138
2022-07-01 20:17:33,980 - octoprint.server.util.sockjs - INFO - New connection from client: ::ffff:192.168.50.138
2022-07-01 20:17:34,030 - octoprint.server.util.flask - INFO - Passively logging in user pougan from ::ffff:192.168.50.138
2022-07-01 20:17:34,031 - octoprint.access.users - INFO - Logged in user: pougan
2022-07-01 20:17:34,614 - octoprint.plugins.softwareupdate - INFO - Fetching check overlays from https://plugins.octoprint.org/update_check_overlay.json
2022-07-01 20:17:37,277 - octoprint.server.util.sockjs - INFO - User pougan logged in on the socket from client ::ffff:192.168.50.138
2022-07-01 20:17:37,567 - octoprint.server.api - ERROR - Error calling SimpleApiPlugin pi_support
Traceback (most recent call last):
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/server/api/__init__.py", line 90, in pluginData
    response = api_plugin.on_api_get(request)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/__init__.py", line 1688, in wrapper
    return f(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_pi_support/__init__.py", line 343, in on_api_get
    result = self.get_additional_environment()
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint/util/__init__.py", line 1688, in wrapper
    return f(*args, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_pi_support/__init__.py", line 323, in get_additional_environment
    self._check_throttled_state()
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_pi_support/__init__.py", line 481, in _check_throttled_state
    state = get_vcgencmd_throttled_state(command)
  File "/home/pi/oprint/lib/python3.7/site-packages/octoprint_pi_support/__init__.py", line 200, in get_vcgencmd_throttled_state
    output, error = sarge.get_both(command, close_fds=CLOSE_FDS)
  File "/home/pi/oprint/lib/python3.7/site-packages/sarge/__init__.py", line 1542, in get_both
    p = capture_both(cmd, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/sarge/__init__.py", line 1512, in capture_both
    return run(cmd, **kwargs)
  File "/home/pi/oprint/lib/python3.7/site-packages/sarge/__init__.py", line 1480, in run
    p.run(input=input, async_=async_)
  File "/home/pi/oprint/lib/python3.7/site-packages/sarge/__init__.py", line 1087, in run
    self.run_node(node, input=input, async_=False)
  File "/home/pi/oprint/lib/python3.7/site-packages/sarge/__init__.py", line 1205, in run_node
    result = getattr(self, method)(node, input, async_)
  File "/home/pi/oprint/lib/python3.7/site-packages/sarge/__init__.py", line 1351, in run_command_node
    node.cmd.run(input=input, async_=async_)
  File "/home/pi/oprint/lib/python3.7/site-packages/sarge/__init__.py", line 691, in run
    s.add_stream(getattr(p, attr))
  File "/home/pi/oprint/lib/python3.7/site-packages/sarge/__init__.py", line 218, in add_stream
    t.start()
  File "/home/pi/oprint/lib/python3.7/site-packages/sentry_sdk/integrations/threading.py", line 54, in sentry_start
    return old_start(self, *a, **kw)
  File "/usr/lib/python3.7/threading.py", line 847, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
2022-07-01 20:17:38,612 - octoprint.plugins.announcements - INFO - Loaded channel _important from https://octoprint.org/feeds/important.xml in 0.46s
2022-07-01 20:17:39,227 - octoprint.plugins.announcements - INFO - Loaded channel _releases from https://octoprint.org/feeds/releases.xml in 0.49s
2022-07-01 20:17:39,787 - octoprint.plugins.announcements - INFO - Loaded channel _blog from https://octoprint.org/feeds/octoblog.xml in 0.5s

```</small>

Please try. The issues of being unable to start a new thread could be plugin related. I think (but can't completely remember) it could be memory related, if it is using too much memory more threads can't be started.

I'd guess from the traceback that this is a SimplyPrint issue and should be reported to them.

So in safe mode if I try to print something it crashes. I've tried disabling a few of the plugins to see if that helps. If I have issues again I'll try disabling the simplyprint plugin. If that solves the issue I'll reach out to them. Though having used vanilla octoprint for so long with no issues I may just reflash normal octopi and give up on simplyprint.

Just an update. I disabled a bunch of extra plugins (besides SimplyPrint) and it actually reconnected. So it might really have been running out of memory. I ended up reflashing to just regular OctoPi and everything is operating normally now. Thanks all for your input!