Removed spurious static_path.
[smonitor.git] / monitor / cherrypy / test / _test_states_demo.py
blob3f8f196c38a88de8155520e44ebc4792da711cc2
1 import os
2 import sys
3 import time
4 starttime = time.time()
6 import cherrypy
9 class Root:
11 def index(self):
12 return "Hello World"
13 index.exposed = True
15 def mtimes(self):
16 return repr(cherrypy.engine.publish("Autoreloader", "mtimes"))
17 mtimes.exposed = True
19 def pid(self):
20 return str(os.getpid())
21 pid.exposed = True
23 def start(self):
24 return repr(starttime)
25 start.exposed = True
27 def exit(self):
28 # This handler might be called before the engine is STARTED if an
29 # HTTP worker thread handles it before the HTTP server returns
30 # control to engine.start. We avoid that race condition here
31 # by waiting for the Bus to be STARTED.
32 cherrypy.engine.wait(state=cherrypy.engine.states.STARTED)
33 cherrypy.engine.exit()
34 exit.exposed = True
37 def unsub_sig():
38 cherrypy.log("unsubsig: %s" % cherrypy.config.get('unsubsig', False))
39 if cherrypy.config.get('unsubsig', False):
40 cherrypy.log("Unsubscribing the default cherrypy signal handler")
41 cherrypy.engine.signal_handler.unsubscribe()
42 try:
43 from signal import signal, SIGTERM
44 except ImportError:
45 pass
46 else:
47 def old_term_handler(signum=None, frame=None):
48 cherrypy.log("I am an old SIGTERM handler.")
49 sys.exit(0)
50 cherrypy.log("Subscribing the new one.")
51 signal(SIGTERM, old_term_handler)
52 cherrypy.engine.subscribe('start', unsub_sig, priority=100)
55 def starterror():
56 if cherrypy.config.get('starterror', False):
57 zerodiv = 1 / 0
58 cherrypy.engine.subscribe('start', starterror, priority=6)
60 def log_test_case_name():
61 if cherrypy.config.get('test_case_name', False):
62 cherrypy.log("STARTED FROM: %s" % cherrypy.config.get('test_case_name'))
63 cherrypy.engine.subscribe('start', log_test_case_name, priority=6)
66 cherrypy.tree.mount(Root(), '/', {'/': {}})