-
Notifications
You must be signed in to change notification settings - Fork 198
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
Conversation
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.
@WardLT you might be interested in this - I think the same choices could be applied to the ParslPoolExecutor when used as a context manager. |
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() |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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.
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