Skip to content

Commit

Permalink
Mitigate Shutdown RuntimeError
Browse files Browse the repository at this point in the history
With the switch to python 3.12 the log started registering a RuntimeError
due to a race condition.

```
systemd[1]: Stopping Fishtest Server port 6543...
pserve[17032]: flush
pserve[17032]: .....................done
pserve[17032]: Exception in thread Thread-740:
pserve[17032]: Traceback (most recent call last):
pserve[17032]:   File "/home/fishtest/.pyenv/versions/3.12.2/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
pserve[17032]:     self.run()
pserve[17032]:   File "/home/fishtest/.pyenv/versions/3.12.2/lib/python3.12/threading.py", line 1431, in run
pserve[17032]:     self.function(*self.args, **self.kwargs)
pserve[17032]:   File "/home/fishtest/fishtest/server/fishtest/rundb.py", line 451, in flush_buffers
pserve[17032]:     self.start_timer()
pserve[17032]:   File "/home/fishtest/fishtest/server/fishtest/rundb.py", line 365, in start_timer
pserve[17032]:     self.timer.start()
pserve[17032]:   File "/home/fishtest/.pyenv/versions/3.12.2/lib/python3.12/threading.py", line 992, in start
pserve[17032]:     _start_new_thread(self._bootstrap, ())
pserve[17032]: RuntimeError: can't create new thread at interpreter shutdown
systemd[1]: Stopped Fishtest Server port 6543.
```

This is the issue opened upstream:
python/cpython#115533
  • Loading branch information
ppigazzini committed Apr 4, 2024
1 parent c59a834 commit b86b1aa
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/fishtest/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,13 @@ def get_run(self, r_id):
return None

def start_timer(self):
self.timer = threading.Timer(1.0, self.flush_buffers)
self.timer.start()
try:
self.timer = threading.Timer(1.0, self.flush_buffers)
self.timer.start()
except RuntimeError as e:
# RuntimeError that doesn't involve interpreter shutdown
if "interpreter shutdown" not in str(e):
raise

def buffer(self, run, flush):
with self.run_cache_lock:
Expand Down

0 comments on commit b86b1aa

Please sign in to comment.