Embeded debugging shell

This commit is contained in:
Julien Duponchelle 2015-02-20 22:40:20 +01:00
parent a0f4c6d021
commit 45a48cfcc1
2 changed files with 11 additions and 0 deletions

View File

@ -107,6 +107,7 @@ def parse_arguments(argv, config):
parser.add_argument("-q", "--quiet", action="store_true", help="do not show logs on stdout") parser.add_argument("-q", "--quiet", action="store_true", help="do not show logs on stdout")
parser.add_argument("-d", "--debug", action="store_true", help="show debug logs") parser.add_argument("-d", "--debug", action="store_true", help="show debug logs")
parser.add_argument("--live", action="store_true", help="enable code live reload") parser.add_argument("--live", action="store_true", help="enable code live reload")
parser.add_argument("--shell", action="store_true", help="start a shell inside the server (debugging purpose only you need to install ptpython before)")
return parser.parse_args(argv) return parser.parse_args(argv)
@ -124,6 +125,7 @@ def set_config(args):
server_config["certkey"] = args.certkey server_config["certkey"] = args.certkey
server_config["debug"] = str(args.debug) server_config["debug"] = str(args.debug)
server_config["live"] = str(args.live) server_config["live"] = str(args.live)
server_config["shell"] = str(args.shell)
config.set_section_config("Server", server_config) config.set_section_config("Server", server_config)

View File

@ -139,6 +139,11 @@ class Server:
raise SystemExit raise SystemExit
return ssl_context return ssl_context
@asyncio.coroutine
def start_shell(self):
from ptpython.repl import embed
yield from embed(globals(), locals(), return_asyncio_coroutine=True, patch_stdout=True)
def run(self): def run(self):
""" """
Starts the server. Starts the server.
@ -176,4 +181,8 @@ class Server:
if server_config.getboolean("live"): if server_config.getboolean("live"):
log.info("Code live reload is enabled, watching for file changes") log.info("Code live reload is enabled, watching for file changes")
self._loop.call_later(1, self._reload_hook) self._loop.call_later(1, self._reload_hook)
if server_config.getboolean("shell"):
asyncio.async(self.start_shell())
self._loop.run_forever() self._loop.run_forever()