squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

Unhandled exception in event loop #164

Closed hanymorcos closed 4 years ago

hanymorcos commented 5 years ago

Is that on the list of issues?

wrk -t12 -c400 -d30s

versions/3.6.9/lib/python3.6/site-packages/japronto/app/init.py", line 86, in default_error_handler text=tb if self._debug else 'Internal Server Error') RuntimeError: Request.Response can only be called once per request ValueError: View did not return Response instance Unhandled exception in event loop

eirnym commented 4 years ago

You should change return type of your function to return a Response instance instead of anything else.

hanymorcos commented 4 years ago

import random from japronto import Application

def generaterandom(request): number = random.randint(0, 100) result = {'lowerLimit': 0, 'higherLimit': 100, 'number': number} request.Response(json=result)

app = Application() r = app.router r.add_route('/number', generaterandom, method='GET') app.run()

Is "json" not a valid return type?

hanymorcos commented 4 years ago

I will try text.