-
-
Save j0e1in/3e8f7760917daa8842f0a91b265d4eb8 to your computer and use it in GitHub Desktop.
A sanic entry-script for development (supports auo-reload, shell-mode)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from app import app | |
def main(): | |
parser = argparse.ArgumentParser( | |
description='Sanic test server', | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter | |
) | |
parser.add_argument('--host', dest='host', default='0.0.0.0') | |
parser.add_argument('--port', dest='port', type=int, default=8600) | |
parser.add_argument('--reload', dest='reload', action='store_true') | |
parser.add_argument('--shell', dest='shell', action='store_true', | |
help='Launch an ipython shell after server start') | |
parser.add_argument('--shell-point', dest='shell_point', | |
default='after_server_start', | |
help='before_server_start | after_server_start') | |
args = parser.parse_args() | |
if args.reload: | |
import hupper | |
reloader = hupper.start_reloader('run.main') | |
reloader.watch_files([]) | |
if args.shell: | |
@app.listener(args.shell_point) | |
async def launch_shell(app, loop): | |
import IPython | |
IPython.embed() | |
app.run(host=args.host, port=args.port) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment