I have post_save signal on one of my models which calls json.dumps on a large python dictionary. I want to call this json.dumps in a separate thread so it may not slow down the save call on my model. I was wondering if it is okay to spawn a new thread from inside a post_save signal? I have read that post_save signals are themselves thread so would it be okay to spawn another Python thread from it?
EDIT: I cannot use a celery task for some reason.
It's not a direct answer to your question but I found this hint from one of the answers in Is Django post_save signal asynchronous?. My post_save signal handler creates a Celery task.
I don't know where you would have read that signals are executed in threads, because it is not at all true. Django does not do anything with threads, and neither should you: if you want to execute something out of process, use a task queue system like Celery.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With