From f16ea20de5fa844c53639f91cf521d2993806fb8 Mon Sep 17 00:00:00 2001 From: Raphael Deem Date: Fri, 18 Nov 2016 17:06:16 -0800 Subject: [PATCH 1/2] provide default app name --- sanic/sanic.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sanic/sanic.py b/sanic/sanic.py index edb3a973..cbc12278 100644 --- a/sanic/sanic.py +++ b/sanic/sanic.py @@ -1,7 +1,7 @@ from asyncio import get_event_loop from collections import deque from functools import partial -from inspect import isawaitable +from inspect import isawaitable, stack, getmodulename from multiprocessing import Process, Event from signal import signal, SIGTERM, SIGINT from time import sleep @@ -18,7 +18,10 @@ from .exceptions import ServerError class Sanic: - def __init__(self, name, router=None, error_handler=None): + def __init__(self, name=None, router=None, error_handler=None): + if name is None: + frame_records = stack()[1] + name = getmodulename(frame_records[1]) self.name = name self.router = router or Router() self.error_handler = error_handler or Handler(self) From 8be4dc8fb52f27a4a51cc5d31a1aa6a767450450 Mon Sep 17 00:00:00 2001 From: Raphael Deem Date: Fri, 18 Nov 2016 17:22:16 -0800 Subject: [PATCH 2/2] update readme example to use default --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cc309c8c..4b6d87de 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ All tests were run on an AWS medium instance running ubuntu, using 1 process. E from sanic import Sanic from sanic.response import json -app = Sanic(__name__) +app = Sanic() @app.route("/") async def test(request):