Are Django Signals Safe?

If I disconnect and connect some signals in the context of one thread, will this affect the signal pool used by other threads?

UPDATE
I will try to be more specific.

I use post_save and pre_delete signals for several senders, which trigger full-text reindexing for a particular model (one specific model), which is the main source of content for the full-text engine.

Re-indexing is done through Celery tasks, and signal handlers simply send re-defined tasks to brokers (in my case, Redis).

Some post_save signals should not cause reindexing (that is, they should not send Celery tasks, pre_delete should always trigger a re-call), because some changes to the model are not related to the full-text engine (for example, status changes, time stamp changes and some others). I cannot check update_fields in the kwargs handler for each case, because, as I noticed, the admin site save operations do not indicate them.

I use a custom context manager that disables the reindexing of handlers from post_save signals for certain senders, gives me the opportunity to return to the call of a part of the code, then the operation on the model is saved, and when the control is passed back to the context manager, all reindexing handlers are reconnected to post_save messages for specific senders.

I want to be sure that this disconnect / connect procedure in the context manager, performed in the context of one thread, will not affect the other threads (that is, all signals disconnected in the context of one thread will still be connected in other threads).

Thanks! unkletee

+4
source share

All Articles