Ticket #7676: threadsafe_serializers.diff

File threadsafe_serializers.diff, 1.3 KB (added by mrts, 16 years ago)

Threadsafe initialization of the _serializers dict

  • django/core/serializers/__init__.py

     
    3434
    3535_serializers = {}
    3636
    37 def register_serializer(format, serializer_module):
     37def register_serializer(serializers, format, serializer_module):
    3838    """Register a new serializer by passing in a module name."""
    3939    module = __import__(serializer_module, {}, {}, [''])
    40     _serializers[format] = module
     40    serializers[format] = module
    4141
    4242def unregister_serializer(format):
    4343    """Unregister a given serializer"""
     
    8888    that user code has a chance to (e.g.) set up custom settings without
    8989    needing to be careful of import order.
    9090    """
     91    global _serializers
     92    serializers = {}
    9193    for format in BUILTIN_SERIALIZERS:
    92         register_serializer(format, BUILTIN_SERIALIZERS[format])
     94        register_serializer(serializers, format, BUILTIN_SERIALIZERS[format])
    9395    if hasattr(settings, "SERIALIZATION_MODULES"):
    9496        for format in settings.SERIALIZATION_MODULES:
    95             register_serializer(format, settings.SERIALIZATION_MODULES[format])
     97            register_serializer(serializers, format,
     98                    settings.SERIALIZATION_MODULES[format])
     99    _serializers = serializers
Back to Top