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

No non-blocking way to start the server in the same thread/loop #27

Open natfarleydev opened 7 years ago

natfarleydev commented 7 years ago

Currently, there is no non-blocking way to start the server in the same thread/loop, because App.run starts the loop itself. Ideally, App.run would be a coroutine and leave starting the loop to the user of the library

However, another way to achieve this would be to have a App.create_serve_coro function (based on https://github.com/squeaky-pl/japronto/blob/master/src/japronto/app/__init__.py#L154 and App.run) which returns a ready made coroutine for passing to the loop, instead of starting the loop itself.

Doing things this way allows for greater flexibility, and allows other libraries to use the loop (e.g. another server running asynchronously along side japronto)

(This is a similar issue to https://github.com/channelcat/sanic/issues/275 where there's more discussion on pros/cons of this approach)