Don't join the command thread if we stop via command socket

If we stop the scheduler via the command socket the stop method fails
with [1] because it tries to join the command thread which is the
thread that runs the stop function. Check for that to make stopping
via 'zuul-scheduler stop' work.

[1] Traceback
ERROR zuul.Scheduler: Exception while processing command
Traceback (most recent call last):
  File "/opt/zuul/lib/python3.8/site-packages/zuul/scheduler.py", line 339, in runCommand
    self.command_map[command]()
  File "/opt/zuul/lib/python3.8/site-packages/zuul/scheduler.py", line 326, in stop
    self.command_thread.join()
  File "/usr/local/lib/python3.8/threading.py", line 1008, in join
    raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread

Change-Id: Icf711d5420eebcd24e0ca2c03ad95b416dad1274
This commit is contained in:
Tobias Henkel 2022-01-11 22:42:20 +01:00
parent 02efa8fb28
commit 14785d2a21
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
1 changed files with 3 additions and 1 deletions

View File

@ -321,7 +321,9 @@ class Scheduler(threading.Thread):
self._command_running = False
self.log.debug("Stopping command socket")
self.command_socket.stop()
self.command_thread.join()
# If we stop from the command socket we cannot join the command thread.
if threading.current_thread() is not self.command_thread:
self.command_thread.join()
self.log.debug("Stopping timedb thread")
self.times.join()
self.log.debug("Stopping monitoring server")