Commit a1764bc3458b605cedb33ff89c3ac2776ddd153a
1 parent
1edf739f
Exists in
master
and in
1 other branch
- Ctrl-C asks for confirmation before exiting
Showing
2 changed files
with
15 additions
and
6 deletions
Show diff stats
BUGS.md
| ... | ... | @@ -7,8 +7,6 @@ |
| 7 | 7 | - periodicamente, cada user faz um post keep-alive. warning nos logs se offline. |
| 8 | 8 | - Cada pergunta respondida é logo submetida. |
| 9 | 9 | - submissao faz um post ajax. |
| 10 | - | |
| 11 | -- ctrl-c should ask for confirmation before exiting. | |
| 12 | 10 | - eventos unfocus? |
| 13 | 11 | - servidor nao esta a lidar com eventos scroll/resize. ignorar? |
| 14 | 12 | |
| ... | ... | @@ -46,6 +44,7 @@ |
| 46 | 44 | |
| 47 | 45 | # FIXED |
| 48 | 46 | |
| 47 | +- ctrl-c should ask for confirmation before exiting. | |
| 49 | 48 | - md_to_html() nao usa o segundo argumento q. pode retirar-se dos templates? |
| 50 | 49 | - config/logger.yaml ainda é do cherrypy... |
| 51 | 50 | - uniformizar question.py com a de aprendizations... | ... | ... |
serve.py
| ... | ... | @@ -9,7 +9,7 @@ import json |
| 9 | 9 | import base64 |
| 10 | 10 | import uuid |
| 11 | 11 | # from mimetypes import guess_type |
| 12 | - | |
| 12 | +import signal | |
| 13 | 13 | |
| 14 | 14 | # packages |
| 15 | 15 | import tornado.ioloop |
| ... | ... | @@ -314,6 +314,14 @@ class AdminHandler(BaseHandler): |
| 314 | 314 | |
| 315 | 315 | |
| 316 | 316 | # ------------------------------------------------------------------------- |
| 317 | +def signal_handler(signal, frame): | |
| 318 | + r = input(' --> Stop webserver? (yes/no) ') | |
| 319 | + if r in ('yes', 'YES'): | |
| 320 | + tornado.ioloop.IOLoop.current().stop() | |
| 321 | + logging.critical('Webserver stopped.') | |
| 322 | + sys.exit(0) | |
| 323 | + | |
| 324 | +# ------------------------------------------------------------------------- | |
| 317 | 325 | # Tornado web server |
| 318 | 326 | # ------------------------------------------------------------------------- |
| 319 | 327 | def main(): |
| ... | ... | @@ -370,14 +378,16 @@ def main(): |
| 370 | 378 | http_server.listen(8443) |
| 371 | 379 | |
| 372 | 380 | # --- run webserver |
| 373 | - logging.info('Webserver running...') | |
| 381 | + signal.signal(signal.SIGINT, signal_handler) | |
| 374 | 382 | |
| 375 | 383 | try: |
| 384 | + logging.info('Webserver running... (Ctrl-C to stop)') | |
| 376 | 385 | tornado.ioloop.IOLoop.current().start() # running... |
| 377 | - except KeyboardInterrupt: | |
| 386 | + except Exception: | |
| 387 | + logging.critical('Webserver stopped.') | |
| 378 | 388 | tornado.ioloop.IOLoop.current().stop() |
| 389 | + raise | |
| 379 | 390 | |
| 380 | - logging.critical('Webserver stopped.') | |
| 381 | 391 | |
| 382 | 392 | # ------------------------------------------------------------------------- |
| 383 | 393 | if __name__ == "__main__": | ... | ... |