thread_inherit_context, upgrade threading & contextvar #6727
thread_inherit_context, upgrade threading & contextvar #6727youknowone merged 3 commits intoRustPython:mainfrom
Conversation
📝 WalkthroughWalkthroughAdds a new boolean setting Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
63912db to
b85ba35
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@crates/vm/src/vm/setting.rs`:
- Around line 91-92: The CLI parser never wires the
Settings.thread_inherit_context flag into the -X option match, so -X
thread_inherit_context has no effect; update the match in the -X parsing logic
(the code handling dev, faulthandler, warn_default_encoding, etc.) to handle the
"thread_inherit_context" token and set sys.flags.thread_inherit_context (or
Settings.thread_inherit_context) to true when seen (and handle disabling if
parser supports "no_thread_inherit_context" or "thread_inherit_context=0");
ensure you reference the same flag name (thread_inherit_context) and the
Settings/sys.flags field so the value flows from CLI into Settings.
🧹 Nitpick comments (1)
crates/vm/src/stdlib/sys.rs (1)
1329-1329: Consider adding sys.flags coverage for the new flag.Given the PR note about pending tests, please add/extend tests to assert
sys.flags.thread_inherit_contextfor both default and enabled configurations.If you want, I can draft the test updates.
b85ba35 to
a674563
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/settings.rs`:
- Around line 314-327: The PYTHON_THREAD_INHERIT_CONTEXT env handling currently
runs after the -X thread_inherit_context option and thus overrides the X-option;
move the shown get_env("PYTHON_THREAD_INHERIT_CONTEXT") block so it executes
before the code that parses/handles the -X thread_inherit_context option (the
block that sets settings.thread_inherit_context from the -X flag), ensuring the
command-line -X thread_inherit_context takes precedence (consistent with
int_max_str_digits behavior).
| if let Some(val) = get_env("PYTHON_THREAD_INHERIT_CONTEXT") { | ||
| settings.thread_inherit_context = match val.to_str() { | ||
| Some("1") => true, | ||
| Some("0") => false, | ||
| _ => { | ||
| error!( | ||
| "Fatal Python error: config_init_thread_inherit_context: \ | ||
| PYTHON_THREAD_INHERIT_CONTEXT=N: N is missing or invalid\n\ | ||
| Python runtime state: preinitialized" | ||
| ); | ||
| std::process::exit(1); | ||
| } | ||
| }; | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check PYTHONINTMAXSTRDIGITS and int_max_str_digits handling to compare precedence
# Look for PYTHONINTMAXSTRDIGITS handling
rg -n -B5 -A10 "PYTHONINTMAXSTRDIGITS" src/settings.rs
# Check int_max_str_digits processing order
echo "---"
rg -n "int_max_str_digits" src/settings.rsRepository: RustPython/RustPython
Length of output: 1647
🏁 Script executed:
#!/bin/bash
# Get detailed view of lines 288-327 to see the exact order of processing
sed -n '280,330p' src/settings.rs | cat -nRepository: RustPython/RustPython
Length of output: 2419
Fix precedence: X-option should override environment variable, not vice versa.
The environment variable PYTHON_THREAD_INHERIT_CONTEXT (lines 315-328) is processed after the -X thread_inherit_context option (lines 289-301), causing it to override the X-option. This is inconsistent with the handling of int_max_str_digits, where the X-option is processed last and takes precedence. Reorder to process the environment variable before the X-option block to ensure command-line options take precedence, or document this as intentional behavior if it differs from Python's design.
🤖 Prompt for AI Agents
In `@src/settings.rs` around lines 314 - 327, The PYTHON_THREAD_INHERIT_CONTEXT
env handling currently runs after the -X thread_inherit_context option and thus
overrides the X-option; move the shown get_env("PYTHON_THREAD_INHERIT_CONTEXT")
block so it executes before the code that parses/handles the -X
thread_inherit_context option (the block that sets
settings.thread_inherit_context from the -X flag), ensuring the command-line -X
thread_inherit_context takes precedence (consistent with int_max_str_digits
behavior).
TODO: update testsSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.