Skip to content

Commit

Permalink
Update how aiohttp servers are started
Browse files Browse the repository at this point in the history
  • Loading branch information
bulv1ne committed Aug 6, 2020
1 parent c3d45e0 commit 7e95915
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
from voluptuous import MultipleInvalid


async def init(loop, host, port):
app = web.Application(loop=loop)
app.router.add_route("GET", "/", handle)
def main(host, port):
app = web.Application()
app.add_routes([web.get("/", handle)])

srv = await loop.create_server(app.make_handler(), host, port)
print("Server started at http://{}:{}".format(host, port))
return srv
web.run_app(app, host=host, port=port)


async def handle(request):
Expand Down Expand Up @@ -71,6 +70,4 @@ async def stream_from_image(img, request):
PORT = 8000

if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop, HOST, PORT))
loop.run_forever()
main(HOST, PORT)

0 comments on commit 7e95915

Please sign in to comment.