Link to code
No response
Proposal
the async example provided works for a single application mode (syntax modified for latest release where return_async_server is obsolete):
import asyncio
import uvloop
from sanic import Sanic, response
app = Sanic("Example")
@app.route("/")
async def test(request):
return response.json({"answer": "42"})
async def main():
server = await app.create_server(
port=8000, host="0.0.0.0")
if server is None:
return
await server.startup()
await server.serve_forever()
if __name__ == "__main__":
asyncio.set_event_loop(uvloop.new_event_loop())
asyncio.run(main())
how to make this work for a situation where you have to serve multiple ports?
only main() has to change:
async def main():
server1 = await app.create_server(port=8000, host="0.0.0.0")
server2 = await app.create_server(port=8080, host="0.0.0.0")
if any(server is None for server in [server1, server2]):
return
await asyncio.gather(*[server1.startup(), server2.startup()])
await server2.serve_forever()
The above code does not work, nor any other combination.
What is the right way to start the 2 async servers?
Can the example be updated for 2 ports?
Additional context
No response
Is this a breaking change?
Link to code
No response
Proposal
the async example provided works for a single application mode (syntax modified for latest release where return_async_server is obsolete):
how to make this work for a situation where you have to serve multiple ports?
only main() has to change:
The above code does not work, nor any other combination.
What is the right way to start the 2 async servers?
Can the example be updated for 2 ports?
Additional context
No response
Is this a breaking change?