◐ Shell
reader mode source ↗
Skip to content
Merged
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
15 changes: 12 additions & 3 deletions crates/vm/src/builtins/asyncgenerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ impl PyAsyncGen {
if let Some(finalizer) = finalizer
&& !zelf.inner.closed.load()
{
// Ignore any errors (PyErr_WriteUnraisable)
let obj: PyObjectRef = zelf.to_owned().into();
let _ = finalizer.call((obj,), vm);
}
}

Expand Up @@ -496,11 +501,13 @@ impl PyAsyncGenAThrow {
}
fn yield_close(&self, vm: &VirtualMachine) -> PyBaseExceptionRef {
self.ag.running_async.store(false);
self.state.store(AwaitableState::Closed);
vm.new_runtime_error("async generator ignored GeneratorExit")
}
fn check_error(&self, exc: PyBaseExceptionRef, vm: &VirtualMachine) -> PyBaseExceptionRef {
self.ag.running_async.store(false);
self.state.store(AwaitableState::Closed);
if self.aclose
&& (exc.fast_isinstance(vm.ctx.exceptions.stop_async_iteration)
Expand Down Expand Up @@ -687,12 +694,14 @@ impl IterNext for PyAnextAwaitable {
/// _PyGen_Finalize for async generators
impl Destructor for PyAsyncGen {
fn del(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> {
// Generator isn't paused, so no need to close
if zelf.inner.closed.load() {
return Ok(());
}

Self::call_finalizer(zelf, vm);
Ok(())
}
}
Loading
Toggle all file notes Toggle all file annotations