最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

socket.io - Django not Working in ASGI app in seconddifferent process - Stack Overflow

programmeradmin1浏览0评论

I have Django and FastAPI on process#1, and they work in Sync and Async functions with no problem. I am running the SocketIO app in process#2 with multiprocessing. Process using AsyncServer and ASGIApp.

The problem is that Django works with Sync functions like get() or create(), but if we use aget() or acreate() the process disappears and vanishes. The rest of the line never runs with no error.

self.sio = socketio.AsyncServer(
    async_mode="aiohttp",
    cors_allowed_origins=self.socket_config.cors_allowed_origins,
    always_connect=self.socket_config.always_connect,
    logger=self.logger if self.socket_config.logger else False,
    engineio_logger=self.logger if self.socket_config.engineio_logger else False,
)
self.socket_application = socketio.ASGIApp(self.sio, socketio_path=self.socket_config.socketio_path)

and run it with uvicorn with pro

multiprocessing.Process(
    target=uvicorn.run,
    kwargs={
        "app": "0.0.0.0",
        "host": 8002,
        "port": int(service_config.SERVICE_PORT),
    }, 
    daemon=True
).start()

I have tried to add get_asgi_application() into other_asgi_app of socketio.ASGIApp but nothing changed. I think the problem isn't from the Django setting with async permissions, it is between the ASGIApp and Django. When it logged the self.socket_application from ASGIApp something interesting showed up, ...DjangoDBProcessRemove object ....

I would be looking forward to any help.

Update: If I run the SocketIO application in the main process works just fine. So I did. SocketIO in the main process and FastAPI in the Second with multiprocess, This time FastAPI faced this issue.

发布评论

评论列表(0)

  1. 暂无评论