Version 1 (modified by mrts, 10 years ago) (diff)


Part of DjangoSpecifications

Threading improvements in Django

According to tickets #5632, #6950 and discussions,, at least the following components of Django are not entirely thread-safe:

  • django.template.loader
  • django.db.models
  • django.contrib.sessions

This specification outlines the changes that need to be implemented to solve these issues.

A related task is to identify other components not mentioned here that have threading issues.


Instead of ad-hoc solutions like the one proposed in #5632, there should be a locking module that can be reused.

Four types of locking primitives could be implemented:

  • Django-wide global locks
  • module-level locks
  • class-level locks
  • function-level locks

I don't see any use for a Django-wide lock. Module-level lock is needed for sessions. Class-level locks seem appropriate for models. Template loader could use either a function-level lock or a module-level lock.

Back to Top