Search code examples
pythondjangogrpcdjango-signals

How can I use Django signals outside the Django application?


I have a gRPC server running that responds to external requests. I also have a Django app that takes care of all other web related events. I want to send a signal to the Django app when the gRPC server receives requests. (The gRPC system was already in place. The Django app is an extension)

Since using Django signals outside the app doesn't work (no context), I want another way to send some kind of notification to the app.

I am aware that this is a very unlikely scenario.


Solution

  • I implemented the first method. There could be other ways too.

    1. Works. If you insist on using Django signals, you can start the gRPC server as a thread in asgi.py. This allows it to gain the Django context and you can then create custom signals and use it in your gRPC server code.
    2. By simply using a library like requests in Python, you can create a communication mechanism to reach your Django app.