Issue ResourceWarning if fd is still open and closefd is true.
(zelf: &Py<Self>, source: PyObjectRef, vm: &VirtualMachine)
| 5953 | impl FileIO { |
| 5954 | /// Issue ResourceWarning if fd is still open and closefd is true. |
| 5955 | fn dealloc_warn(zelf: &Py<Self>, source: PyObjectRef, vm: &VirtualMachine) { |
| 5956 | if zelf.fd.load() >= 0 && zelf.closefd.load() { |
| 5957 | let repr = source |
| 5958 | .repr(vm) |
| 5959 | .map(|s| s.as_wtf8().to_owned()) |
| 5960 | .unwrap_or_else(|_| Wtf8Buf::from("<file>")); |
| 5961 | if let Err(e) = crate::stdlib::_warnings::warn( |
| 5962 | vm.ctx.exceptions.resource_warning, |
| 5963 | format!("unclosed file {repr}"), |
| 5964 | 1, |
| 5965 | vm, |
| 5966 | ) { |
| 5967 | vm.run_unraisable(e, None, zelf.as_object().to_owned()); |
| 5968 | } |
| 5969 | } |
| 5970 | } |
| 5971 | } |
| 5972 | |
| 5973 | impl Destructor for FileIO { |