Clean up resources on shutdown.
(self)
| 500 | ) |
| 501 | |
| 502 | def _cleanup(self): |
| 503 | """Clean up resources on shutdown.""" |
| 504 | # Shutdown thread pool executor |
| 505 | if self._executor: |
| 506 | self._executor.shutdown(wait=False, cancel_futures=True) |
| 507 | self._executor = None |
| 508 | |
| 509 | # Close all apps |
| 510 | for path, app in self.apps.items(): |
| 511 | try: |
| 512 | app.close() |
| 513 | self.log.debug("Closed dirty app: %s", path) |
| 514 | except Exception as e: |
| 515 | self.log.error("Error closing dirty app %s: %s", path, e) |
| 516 | |
| 517 | # Close temp file |
| 518 | try: |
| 519 | self.tmp.close() |
| 520 | except Exception: |
| 521 | pass |
| 522 | |
| 523 | # Remove socket file |
| 524 | try: |
| 525 | if os.path.exists(self.socket_path): |
| 526 | os.unlink(self.socket_path) |
| 527 | except Exception: |
| 528 | pass |
| 529 | |
| 530 | self.log.info("Dirty worker %s exiting", self.pid) |