<commit_before>"""Django DDP utils for DDP messaging."""
import collections
from django.core.serializers import get_serializer

_SERIALIZER = None

def obj_change_as_msg(obj, msg):
    """Generate a DDP msg for obj with specified msg type."""
    global _SERIALIZER
    if _SERIALIZER is None:
        _SERIALIZER = get_serializer('ddp')()
    data = _SERIALIZER.serialize([obj])[0]
    name = data['model']

    # cast ID as string<commit_msg>Fix non-threadsafe failure in serializer - now using thread local serializer instance.<commit_after>"""Django DDP utils for DDP messaging."""
from dddp import THREAD_LOCAL as this
from django.core.serializers import get_serializer


def serializer_factory():
    """Make a new DDP serializer."""
    return get_serializer('ddp')()


def obj_change_as_msg(obj, msg):
    """Generate a DDP msg for obj with specified msg type."""
    serializer = this.get('serializer', serializer_factory)
    data = serializer.serialize([obj])[0]
    name = data['model']

    # cast ID as string
{'fraction_non_alphanumeric': 0.10654936461388075, 'fraction_numerical': 0.0019550342130987292, 'mean_word_length': 4.278350515463917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '44804', 'n_tokens_mistral': 316, 'n_tokens_neox': 311, 'n_words': 101}