Hi, I’m new here and would like to ask a question regarding Sanic.
The problem I am facing is that I want to have a producer-consumer design where the consumer is running in the background and producer is running at the http end.
something like:
from sanic import Sanic, response
from asyncio import Queue
app = Sanic(__name__)
q = Queue()
@app.get("/")
async def place_something_on_the_q(request):
await q.put("item 1")
return response.json({})
async def consume(app):
while 1:
t = await q.get()
print(t)
app.add_task(consume)
if __name__ == "__main__":
app.run(host="localhost", port="4000")
The problem is that the background tasks runs in another loop. Is it possible to specify the same loop?