Repository navigation
Align shutdown flush and unraisable reporting with CPython #9690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b9a4ddf
7731dac
63bd251
3735687
4f9197e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -816,6 +816,25 @@ mod builtins { | |
| obj.get_id() | ||
| } | ||
|
|
||
| thread_local! { | ||
| // Rustyline retains input read ahead past the current line. Keep the | ||
| // editor across input() calls so that queued lines are not discarded. | ||
| // It contains no Python objects or interpreter-specific helper state. | ||
| static INPUT_READLINE: core::cell::RefCell<Option<Readline<()>>> = | ||
| core::cell::RefCell::new(Some(Readline::new(()))); | ||
|
Comment on lines
+823
to
+824
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invalidate the cached reader when the terminal changes. If a caller changes
|
||
| } | ||
|
|
||
| struct InputReadlineGuard<'a> { | ||
| slot: &'a core::cell::RefCell<Option<Readline<()>>>, | ||
| reader: Option<Readline<()>>, | ||
| } | ||
|
|
||
| impl Drop for InputReadlineGuard<'_> { | ||
| fn drop(&mut self) { | ||
| *self.slot.borrow_mut() = self.reader.take(); | ||
| } | ||
| } | ||
|
|
||
| #[pyfunction] | ||
| fn input(args: InputArgs, vm: &VirtualMachine) -> PyResult { | ||
| let prompt = args.prompt; | ||
|
|
@@ -867,8 +886,20 @@ mod builtins { | |
|
|
||
| if use_rustyline { | ||
| let prompt = prompt_str.unwrap(); | ||
| let mut readline = Readline::new(()); | ||
| match readline.readline(prompt) { | ||
| let result = INPUT_READLINE.with(|slot| -> PyResult<_> { | ||
| // Do not keep a RefCell borrow alive while reading. An empty | ||
| // slot means a nested call, which must not create another | ||
| // editor and consume or discard the outer reader's input. | ||
| let reader = slot.borrow_mut().take(); | ||
| let reader = | ||
| reader.ok_or_else(|| vm.new_runtime_error("reentrant call inside input"))?; | ||
| let mut guard = InputReadlineGuard { | ||
| slot, | ||
| reader: Some(reader), | ||
| }; | ||
| Ok(guard.reader.as_mut().unwrap().readline(prompt)) | ||
| })?; | ||
| match result { | ||
| ReadlineResult::Line(s) => Ok(vm.ctx.new_str(s).into()), | ||
| ReadlineResult::Eof => { | ||
| Err(vm.new_exception_empty(vm.ctx.exceptions.eof_error.to_owned())) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: RustPython/RustPython
Length of output: 3763
Script executed:
Repository: RustPython/RustPython
Length of output: 42379
Script executed:
Repository: RustPython/RustPython
Length of output: 10575
Add
write_noraiseto the unsupportedcrt_fdimplementation.threadingenablesshutdown_io_lockindependently ofhost_env. On wasm32 targets other than WASI,crt_fdresolves tocrt_fd_unsupported.rs, which has nowrite_noraise, so the call at this line can fail to compile.Preserve the abort path and return the unsupported descriptor error from the fallback:
Suggested fix