Skip to content

Conversation

@ianjosephwilson
Copy link
Contributor

  • Move low level placeholder operations and constants into placeholder config helper class.
  • This is to avoid potential free-threading issues but overall we probably shouldn't be using dynamic module level variables anyways.
  • Long term we probably want to share the placeholder configuration across a "group" of parsers but I think this is ok for now.

@pauleveritt
Copy link
Contributor

Thanks for doing this. Once this is merged, I'll switch my aria-testing package (which I use heavily in other packages) to free threading and see if I spot any problems. I'll also put the pytest-freethreaded stuff in that package and keep trying to trigger.

As a note, the only potential (but unlikely) other issue CC found:

🟡 POTENTIAL ISSUE: Mutable Dataclass Children (nodes.py, parser.py)

@dataclass
class OpenTElement:
    tag: str
    attrs: tuple[TAttribute, ...]
    children: list[TNode] = field(default_factory=list)  # Mutable!

Problem: list is mutable. If multiple threads access/modify the same OpenTElement's children, race conditions occur.

Current Safety: These are created per-parse operation and not shared between threads, so likely safe in practice.

Impact: LOW - Only matters if users share parser objects across threads (discouraged pattern)

@ianjosephwilson
Copy link
Contributor Author

Yeah I don't think there is any use-case where parsing the same template across threads or even asyncio workers would make any sense. We can just ignore that for the foreseeable future. I'm not even sure the use-case for free threading but it will probably help avoid regular threading issues at the same time. We might have to do something to protect whatever cache we end up using from getting stampeded on startup but I think that's for later.

@pauleveritt
Copy link
Contributor

Apologies, I should have framed this better. It's less about making tdom take advantage of threads and more about getting it marked as safe in a ft application. 😉 But I'm ok with just closing this PR if you'd like.

@davepeck
Copy link
Contributor

davepeck commented Jan 5, 2026

@ianjosephwilson Thanks! I'm back and starting to look over tdom stuff, although it's likely not until later this week when I'll have time to really dig in. This is great, though; merging.

@davepeck davepeck merged commit ccf05aa into t-strings:main Jan 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants