Django and thread safety

If I read the django documentation, only the template tag documents indicate a potential thread safety hazard.

However, I'm curious what should I do / avoid writing thread-safe code in Django ...

One example: I have the following function to configure the loggers used in django.

_LOGGER_CONFIGURED = False

def config_logger():
    global _LOGGER_CONFIGURED
    if _LOGGER_CONFIGURED: return
    _LOGGER_CONFIGURED = True

    rootlogger = logging.getLogger('')
    stderr_handler = StreamHandler(sys.stderr)
    rootlogger.addHandler(stderr_handler)

and at the end of my root urlconf, I have the following function call:

config_logger()

The question arises:

  • Is this code unsafe?

  • What variables are shared between django threads?

+3
source share
1 answer

django , , , , , , . django, , , cycle.

, : logging , , logging.getLogger , logging LOGGING_CONFIG settings.py. .

, , - . , PostgreSQL MySQL/INNOdb, concurrency shennanegans.

+1

Source: https://habr.com/ru/post/1776307/


All Articles