(zelf: &Py<Self>, vm: &VirtualMachine)
| 783 | |
| 784 | impl Destructor for PyFuture { |
| 785 | fn del(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<()> { |
| 786 | // Check if we should log the traceback |
| 787 | // Don't log if log_tb is false or if the future was cancelled |
| 788 | if !zelf.fut_log_tb.load(Ordering::Relaxed) { |
| 789 | return Ok(()); |
| 790 | } |
| 791 | |
| 792 | if zelf.fut_state.load() == FutureState::Cancelled { |
| 793 | return Ok(()); |
| 794 | } |
| 795 | |
| 796 | let exc = zelf.fut_exception.read().clone(); |
| 797 | let exc = match exc { |
| 798 | Some(e) => e, |
| 799 | None => return Ok(()), |
| 800 | }; |
| 801 | |
| 802 | let loop_obj = zelf.fut_loop.read().clone(); |
| 803 | let loop_obj = match loop_obj { |
| 804 | Some(l) => l, |
| 805 | None => return Ok(()), |
| 806 | }; |
| 807 | |
| 808 | // Create context dict for call_exception_handler |
| 809 | let context = PyDict::default().into_ref(&vm.ctx); |
| 810 | let class_name = zelf.class().name().to_string(); |
| 811 | let message = format!("{} exception was never retrieved", class_name); |
| 812 | context.set_item( |
| 813 | vm.ctx.intern_str("message"), |
| 814 | vm.ctx.new_str(message).into(), |
| 815 | vm, |
| 816 | )?; |
| 817 | context.set_item(vm.ctx.intern_str("exception"), exc, vm)?; |
| 818 | context.set_item(vm.ctx.intern_str("future"), zelf.to_owned().into(), vm)?; |
| 819 | |
| 820 | if let Some(tb) = zelf.fut_source_tb.read().clone() { |
| 821 | context.set_item(vm.ctx.intern_str("source_traceback"), tb, vm)?; |
| 822 | } |
| 823 | |
| 824 | // Call loop.call_exception_handler(context) |
| 825 | let _ = vm.call_method(&loop_obj, "call_exception_handler", (context,)); |
| 826 | Ok(()) |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | impl Representable for PyFuture { |
nothing calls this directly
no test coverage detected