Description
Is it possible to use BackgroundTasks with websockets?
I tried with a simple case:
def test():
print('test')
@router.post("/test")
async def send_notification(background_tasks: BackgroundTasks):
background_tasks.add_task(test)
return {"message": "Notification sent in the background"}
@router.websocket("/ws")
async def listen(websocket: WebSocket, background_tasks: BackgroundTasks):
await websocket.accept()
background_tasks.add_task(test)
The send_notification http endpoint example works, but the listen websocket endpoint doesn't.
Thanks!
Description
Is it possible to use BackgroundTasks with websockets?
I tried with a simple case:
The
send_notificationhttp endpoint example works, but thelistenwebsocket endpoint doesn't.Thanks!