1. cherrypy
  2. CherryPy


Robert Brewer  committed c7d8465

Added a warning and auto-exit on main thread exit if the Bus is not shut down. This will help avoid issues like #750.

  • Participants
  • Parent commits 5481473
  • Branches default

Comments (0)

Files changed (1)

File cherrypy/restsrv/wspbus.py

View file
+import atexit
 import os
 import threading
 import time
 import traceback as _traceback
+import warnings
 # Use a flag to indicate the state of the bus.
         return output
+    def _clean_exit(self):
+        """An atexit handler which asserts the Bus is not running."""
+        if self.state != states.EXITING:
+            warnings.warn(
+                "The main thread is exiting, but the Bus is in the %r state; "
+                "shutting it down automatically now. You must either call "
+                "bus.block() after start(), or call bus.exit() before the "
+                "main thread exits." % self.state, RuntimeWarning)
+            self.exit()
     def start(self):
         """Start all services."""
+        atexit.register(self._clean_exit)
         self.state = states.STARTING
         self.log('Bus STARTING')