5

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.

Rafay
  • 6,108
  • 11
  • 51
  • 71

2 Answers2

2

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.

Community
  • 1
  • 1
f01
  • 1,738
  • 1
  • 18
  • 21
1

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.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895