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

Method exit

crates/stdlib/src/contextvars.rs:108–127  ·  view source on GitHub ↗
(zelf: &Py<Self>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

106 }
107
108 fn exit(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
109 if !zelf.inner.entered.get() {
110 let msg = format!(
111 "cannot exit context: {} is not entered",
112 zelf.as_object().repr(vm)?
113 );
114 return Err(vm.new_runtime_error(msg));
115 }
116
117 super::CONTEXTS.with_borrow_mut(|ctxs| {
118 let err_msg =
119 "cannot exit context: thread state references a different context object";
120 ctxs.pop_if(|ctx| ctx.get_id() == zelf.get_id())
121 .map(drop)
122 .ok_or_else(|| vm.new_runtime_error(err_msg))
123 })?;
124 zelf.inner.entered.set(false);
125
126 Ok(())
127 }
128
129 fn current(vm: &VirtualMachine) -> PyRef<Self> {
130 super::CONTEXTS.with_borrow_mut(|ctxs| {

Callers

nothing calls this directly

Calls 6

ok_or_elseMethod · 0.80
ErrClass · 0.50
getMethod · 0.45
mapMethod · 0.45
get_idMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected