Merge pull request #159 from r0fls/namedefault

provide default app name
This commit is contained in:
Eli Uriegas 2016-11-18 20:47:50 -06:00 committed by GitHub
commit 879b9a4a15
2 changed files with 6 additions and 3 deletions

View File

@ -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 import Sanic
from sanic.response import json from sanic.response import json
app = Sanic(__name__) app = Sanic()
@app.route("/") @app.route("/")
async def test(request): async def test(request):

View File

@ -1,7 +1,7 @@
from asyncio import get_event_loop from asyncio import get_event_loop
from collections import deque from collections import deque
from functools import partial from functools import partial
from inspect import isawaitable from inspect import isawaitable, stack, getmodulename
from multiprocessing import Process, Event from multiprocessing import Process, Event
from signal import signal, SIGTERM, SIGINT from signal import signal, SIGTERM, SIGINT
from time import sleep from time import sleep
@ -18,7 +18,10 @@ from .exceptions import ServerError
class Sanic: 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.name = name
self.router = router or Router() self.router = router or Router()
self.error_handler = error_handler or Handler(self) self.error_handler = error_handler or Handler(self)