Last active
June 17, 2022 06:32
-
-
Save wonderbeyond/c619ef81c44c6037814c50d9d1c5e7a4 to your computer and use it in GitHub Desktop.
A sanic entry-script for development (supports auo-reload, shell-mode)
This file contains hidden or 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