Commit 5476b345352eededeb8b85d767c143dcf66eff68

Authored by Miguel Barão
1 parent 2d620b8a
Exists in master and in 1 other branch dev

- Ask yes/no to confirm stopping the server

Showing 2 changed files with 20 additions and 5 deletions   Show diff stats
@@ -9,6 +9,7 @@ import logging.config @@ -9,6 +9,7 @@ import logging.config
9 import argparse 9 import argparse
10 from concurrent.futures import ThreadPoolExecutor 10 from concurrent.futures import ThreadPoolExecutor
11 import mimetypes 11 import mimetypes
  12 +import signal
12 13
13 # user installed libraries 14 # user installed libraries
14 import tornado.ioloop 15 import tornado.ioloop
@@ -285,6 +286,16 @@ class QuestionHandler(BaseHandler): @@ -285,6 +286,16 @@ class QuestionHandler(BaseHandler):
285 } 286 }
286 }) 287 })
287 288
  289 +
  290 +# -------------------------------------------------------------------------
  291 +def signal_handler(signal, frame):
  292 + r = input(' --> Stop webserver? (yes/no) ')
  293 + if r in ('yes', 'YES'):
  294 + tornado.ioloop.IOLoop.current().stop()
  295 + logging.critical('Webserver stopped.')
  296 + sys.exit(0)
  297 +
  298 +
288 # ------------------------------------------------------------------------- 299 # -------------------------------------------------------------------------
289 # Tornado web server 300 # Tornado web server
290 # ---------------------------------------------------------------------------- 301 # ----------------------------------------------------------------------------
@@ -339,13 +350,17 @@ def main(): @@ -339,13 +350,17 @@ def main():
339 http_server.listen(8443) 350 http_server.listen(8443)
340 351
341 # --- run webserver 352 # --- run webserver
342 - logging.info('Webserver running...') 353 + logging.info('Webserver running... (Ctrl-C to stop)')
  354 + signal.signal(signal.SIGINT, signal_handler)
  355 +
  356 +
343 try: 357 try:
344 tornado.ioloop.IOLoop.current().start() # running... 358 tornado.ioloop.IOLoop.current().start() # running...
345 - except KeyboardInterrupt: 359 + except Exception:
  360 + logging.critical('Webserver stopped.')
346 tornado.ioloop.IOLoop.current().stop() 361 tornado.ioloop.IOLoop.current().stop()
  362 + raise
347 363
348 - logging.critical('Webserver stopped.')  
349 364
350 # ---------------------------------------------------------------------------- 365 # ----------------------------------------------------------------------------
351 if __name__ == "__main__": 366 if __name__ == "__main__":
@@ -16,11 +16,11 @@ from pygments.formatters import HtmlFormatter @@ -16,11 +16,11 @@ from pygments.formatters import HtmlFormatter
16 logger = logging.getLogger(__name__) 16 logger = logging.getLogger(__name__)
17 17
18 18
19 -# --------------------------------------------------------------------------- 19 +# -------------------------------------------------------------------------
20 # Markdown to HTML renderer with support for LaTeX equations 20 # Markdown to HTML renderer with support for LaTeX equations
21 # Inline math: $x$ 21 # Inline math: $x$
22 # Block math: $$x$$ or \begin{equation}x\end{equation} 22 # Block math: $$x$$ or \begin{equation}x\end{equation}
23 -# --------------------------------------------------------------------------- 23 +# -------------------------------------------------------------------------
24 class MathBlockGrammar(mistune.BlockGrammar): 24 class MathBlockGrammar(mistune.BlockGrammar):
25 block_math = re.compile(r"^\$\$(.*?)\$\$", re.DOTALL) 25 block_math = re.compile(r"^\$\$(.*?)\$\$", re.DOTALL)
26 latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}", re.DOTALL) 26 latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}", re.DOTALL)