Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entrypoint.cleanup_multiprocessing_resources #918

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions openadapt/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
"""Entrypoint for OpenAdapt."""

import multiprocessing
import atexit

if __name__ == "__main__":
# This needs to be called before any code that uses multiprocessing
multiprocessing.freeze_support()

from openadapt.build_utils import redirect_stdout_stderr
from openadapt.error_reporting import configure_error_reporting
from openadapt.custom_logger import logger


def cleanup_multiprocessing_resources():
"""Ensure multiprocessing resources are cleaned up."""
from multiprocessing.resource_tracker import _resource_tracker
try:
_resource_tracker._check_alive() # Ensure tracker is running
_resource_tracker._cleanup() # Attempt cleanup
except Exception as exc:
logger.warning(f"Failed to cleanup multiprocessing resources: {exc}")


def run_openadapt() -> None:
"""Run OpenAdapt."""
with redirect_stdout_stderr():
Expand All @@ -27,5 +35,8 @@ def run_openadapt() -> None:
logger.exception(exc)


# Register resource cleanup on exit
atexit.register(cleanup_multiprocessing_resources)

if __name__ == "__main__":
run_openadapt()
Loading