Opened 3 days ago

Closed 3 days ago

#36011 closed Bug (invalid)

Django not Working in ASGI app in second/defferent process

Reported by: Mohammad Mahdi Samei Owned by:
Component: Database layer (models, ORM) Version: 5.1
Severity: Normal Keywords: SocketIO, multiprocessing, FastAPI, ASGI
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (2)

comment:2 by Carlton Gibson, 3 days ago

Resolution: invalid
Status: newclosed

Please don't use this issue tracker for support requests. See TicketClosingReasons/UseSupportChannels

Note: See TracTickets for help on using tickets.
Back to Top