Repository navigation
Add 33 advanced pitfalls: asyncio, threading, interpreter internals, data systems - #2
Merged
Merged
Conversation
…a systems - docs/concurrency.md (20-30): asyncio task garbage collection, forgotten await, blocking the loop, swallowed cancellation, cross-thread loop calls, non-atomic +=, vanishing thread exceptions, Lock re-entry, threading.local under asyncio, fork() deadlocks, daemon threads. - docs/object-model.md (31-37): property vs __getattr__, lru_cache leaks, __eq__ removing __hash__, __exit__ swallowing, weakrefs to bound methods, mock.patch targets, double-imported __main__. - docs/interpreter.md (38-42): -O stripping asserts, class-body comprehension scope, locals() writes, id() reuse, int/str limit. - docs/data-systems.md (43-52): hash() sharding, NaN, nanosecond timestamps, float prices, DST arithmetic, fixed UTC offsets, utcnow(), struct alignment, non-standard JSON. - README: advanced contents table and an "In the wild" section on Home Assistant bug fixes and guard rails, each linked to the PR or source file. Examples 48 and 49 reproduce HA PRs #188537 and #188836. - One self-checking example per pitfall; all 52 run in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff9ec9583a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- examples/24: disable inherited asyncio debug mode before the stall demo. Under PYTHONASYNCIODEBUG=1 or -X dev, call_soon from a thread raised in the worker and the example hung forever. Waits now have a 5s timeout, so a regression fails instead of hanging. - docs/concurrency.md #21: -W error::RuntimeWarning does not fail on a never-awaited coroutine, because the warning fires during finalization and becomes an unraisable exception. Document the pytest filters that do fail (verified with pytest 9.2). - CI: also run every example under -X dev. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Part II of the catalog: 33 advanced pitfalls on four new pages in
docs/, plus an "In the wild" section on how Home Assistant runs into and guards against them. Total goes from 19 to 52, every one with a self-checking example run in CI.New pages
call_soonfrom a thread stalls 500 ms ·threading.localgives Alice's request to Bob ·fork()child deadlocks on a copied lock'Device' object has no attribute 'temperature'·@lru_cachekeeps every instance alive ·mock.patchon the wrong modulepython -Odeletes validation · class-body comprehensions read the global ·id()reuse returning stale cache entries · 4300-digitint/strlimithash()sharding differs per process · floats lose nanoseconds ·datetimemerges trades 500 ns apart ·int(1.15 * 100) == 114· DST arithmetic ·structpadding ·NaNin JSONReal-world sources
block_async_io.py,verify_event_loop_thread(), bugbear rules).int64prices (10⁻⁹ units) and theUNDEF_PRICEsentinel.Determinism
Timing-sensitive pitfalls are forced to fail every time so CI can assert them:
gc.collect()for task collection,time.sleep(0)to widen the race window, a held lock acrossfork(), subprocesses for-O,PYTHONHASHSEEDand daemon threads. #29 and #50 skip on platforms withoutos.forkortime.tzset.Test plan
🤖 Generated with Claude Code