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

Method close

crates/vm/src/stdlib/_io.rs:1780–1799  ·  view source on GitHub ↗
(zelf: PyRef<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1778
1779 #[pymethod]
1780 fn close(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
1781 // Don't hold the lock while calling Python code to avoid reentrant lock issues
1782 let raw = {
1783 let data = zelf.lock(vm)?;
1784 let raw = data.check_init(vm)?;
1785 if file_closed(raw, vm)? {
1786 return Ok(vm.ctx.none());
1787 }
1788 raw.to_owned()
1789 };
1790 if zelf.finalizing().load(Ordering::Relaxed) {
1791 // _dealloc_warn: delegate to raw._dealloc_warn(source)
1792 let _ = vm.call_method(&raw, "_dealloc_warn", (zelf.as_object().to_owned(),));
1793 }
1794 // Set closing flag so that concurrent write() calls will fail
1795 zelf.closing().store(true, Ordering::Release);
1796 let flush_res = vm.call_method(zelf.as_object(), "flush", ()).map(drop);
1797 let close_res = vm.call_method(&raw, "close", ());
1798 exception_chain(flush_res, close_res)
1799 }
1800
1801 #[pymethod]
1802 fn readable(&self) -> bool {

Callers

nothing calls this directly

Implementers 1

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

Calls 13

file_closedFunction · 0.85
exception_chainFunction · 0.85
check_initMethod · 0.80
noneMethod · 0.80
finalizingMethod · 0.80
closingMethod · 0.80
lockMethod · 0.45
to_ownedMethod · 0.45
loadMethod · 0.45
call_methodMethod · 0.45
as_objectMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected