Destructor. Calls close().
(self)
| 396 | self.__closed = True |
| 397 | |
| 398 | def __del__(self): |
| 399 | """Destructor. Calls close().""" |
| 400 | try: |
| 401 | closed = self.closed |
| 402 | except AttributeError: |
| 403 | # If getting closed fails, then the object is probably |
| 404 | # in an unusable state, so ignore. |
| 405 | return |
| 406 | |
| 407 | if closed: |
| 408 | return |
| 409 | |
| 410 | if dealloc_warn := getattr(self, "_dealloc_warn", None): |
| 411 | dealloc_warn(self) |
| 412 | |
| 413 | # If close() fails, the caller logs the exception with |
| 414 | # sys.unraisablehook. close() must be called at the end at __del__(). |
| 415 | self.close() |
| 416 | |
| 417 | ### Inquiries ### |
| 418 |