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

Add exit choices for the DFK context manager #3468

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

benclifford
Copy link
Collaborator

Most important is a wait exit mode which will make the context manager wait for tasks to complete at exit, unless an exception is raised. This addresses a common usability problem where users forget to wait for their tasks and are then confused by their workflow exiting immediately, but does not defer exceptions - this block-on-exception behaviour was the main usability problem when attempting this before in PR #610.

Changed Behaviour

The default mode should preserve existing behaviour - so none.

Type of change

  • New feature

Most important is a ``wait`` exit mode which will make the context manager
wait for tasks to complete at exit, unless an exception is raised. This
addresses a common usability problem where users forget to wait for their
tasks and are then confused by their workflow exiting immediately, but
does not defer exceptions - this block-on-exception behaviour was the main
usability problem when attempting this before in PR #610.
@benclifford
Copy link
Collaborator Author

@WardLT you might be interested in this - I think the same choices could be applied to the ParslPoolExecutor when used as a context manager.

parsl/config.py Outdated Show resolved Hide resolved
parsl/config.py Outdated Show resolved Hide resolved
Comment on lines +223 to +235
if mode == "cleanup":
logger.info("Calling cleanup for DFK")
self.cleanup()
elif mode == "skip":
logger.info("Skipping all cleanup handling")
elif mode == "wait":
if exc_type is None:
logger.info("Waiting for all tasks to complete")
self.wait_for_current_tasks()
self.cleanup()
else:
logger.info("There was an exception - cleaning up without waiting for task completion")
self.cleanup()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If cleanup is the default in almost all cases, could make the code follow "moral" suit. Consider:

# with typeguard, is this, in fact, necessary?
if mode not in ("cleanup", "wait", "skip"):
    raise InternalConsistencyError(f"Exit case for {mode} should be unreachable, validated by typeguard on Config()")

if mode == "skip":
    logger.info("Skipping all cleanup handling")
    return

if mode == "wait":
     if exc_type is None:
        logger.info("Waiting ...")
        self.wait_for_current_tasks()
     else:
        logger.info("was an exc ...")

logger.info("Calling cleanup for DFK")
self.cleanup()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could do - I think it comes down to seeing this case statement as choosing three distinct behaviours vs a "normal flow" that gets ornamented by different things on the way. I've ended up with more of a preference for being explicit about all three flows as explicit separate options, but I think it would be fine either way.

@benclifford benclifford merged commit 219ebb0 into master Jun 10, 2024
6 checks passed
@benclifford benclifford deleted the benc-context-exit-modes branch June 10, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants