MCPcopy Index your code
hub / github.com/RustPython/RustPython / write

Method write

crates/vm/src/stdlib/_io.rs:2015–2042  ·  view source on GitHub ↗
(&self, obj: ArgBytesLike, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2013
2014 #[pymethod]
2015 fn write(&self, obj: ArgBytesLike, vm: &VirtualMachine) -> PyResult<usize> {
2016 // Check if close() is in progress (Issue #31976)
2017 // If closing, wait for close() to complete by spinning until raw is closed.
2018 // Note: This spin-wait has no timeout because close() is expected to always
2019 // complete (flush + fd close).
2020 if self.writer().closing().load(Ordering::Acquire) {
2021 loop {
2022 let raw = {
2023 let data = self.writer().lock(vm)?;
2024 match &data.raw {
2025 Some(raw) => raw.to_owned(),
2026 None => break, // detached
2027 }
2028 };
2029 if file_closed(&raw, vm)? {
2030 break;
2031 }
2032 // Yield to other threads
2033 std::thread::yield_now();
2034 }
2035 return Err(vm.new_value_error("write to closed file"));
2036 }
2037 let mut data = self.writer().lock(vm)?;
2038 let raw = data.check_init(vm)?;
2039 ensure_unclosed(raw, "write to closed file", vm)?;
2040
2041 data.write(obj, vm)
2042 }
2043
2044 #[pymethod]
2045 fn flush(&self, vm: &VirtualMachine) -> PyResult<()> {

Callers

nothing calls this directly

Implementers 1

_io.rscrates/vm/src/stdlib/_io.rs

Calls 10

file_closedFunction · 0.85
ensure_unclosedFunction · 0.85
closingMethod · 0.80
check_initMethod · 0.80
ErrClass · 0.50
loadMethod · 0.45
writerMethod · 0.45
lockMethod · 0.45
to_ownedMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected