Skip to content

Help free threading by replacing random.choices #93

@pauleveritt

Description

@pauleveritt

Rather than open a discussion about free threading, I thought I'd focus on one specific part.

When I asked Claude Code to investigate, it flagged these lines in placeholders.py where set them up. Its findings:

🔴 CRITICAL: Random Global State (placeholders.py:9-12)

FRAGMENT_TAG = f"t🐍f-{''.join(random.choices(string.ascii_lowercase, k=4))}-"
_PLACEHOLDER_PREFIX = f"t🐍{''.join(random.choices(string.ascii_lowercase, k=2))}-"
_PLACEHOLDER_SUFFIX = f"-{''.join(random.choices(string.ascii_lowercase, k=2))}🐍t"

Problem: These are module-level constants generated with random values at import time. In free-threaded mode:

  1. Multiple threads importing simultaneously could cause race conditions
  2. The regex pattern depends on these values - if they're inconsistent, parsing breaks
  3. Module initialization isn't guaranteed to be atomic across threads

Impact: HIGH - Could cause parser failures or incorrect template processing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions