Skip to content

Conversation

@jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented Jul 11, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved task shutdown handling to ensure all pending tasks are fully processed before termination.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 11, 2025

Walkthrough

The update modifies the shutdown logic within the execute_tasks_h5 function by introducing a loop that repeatedly filters and processes pending futures in memory_dict until all are completed. The rest of the shutdown sequence, including task termination and queue cleanup, remains unchanged.

Changes

File(s) Change Summary
executorlib/task_scheduler/file/shared.py Enhanced shutdown logic in execute_tasks_h5 to loop and process all pending futures until completion.

Poem

In the warren where tasks reside,
A loop now checks each side by side.
Futures are watched until they're through,
No bunny left behind in the queue!
When shutdown calls, we sweep the den—
All tasks complete, then rest again.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jan-janssen jan-janssen linked an issue Jul 11, 2025 that may be closed by this pull request
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 957170b and 5a59a1d.

📒 Files selected for processing (1)
  • executorlib/task_scheduler/file/shared.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
  • GitHub Check: unittest_mpich (macos-latest, 3.13)
  • GitHub Check: unittest_openmpi (macos-latest, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.11)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.12)
  • GitHub Check: unittest_old
  • GitHub Check: unittest_flux_openmpi
  • GitHub Check: notebooks_integration
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
  • GitHub Check: notebooks
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
  • GitHub Check: unittest_flux_mpich
  • GitHub Check: unittest_win
  • GitHub Check: pip_check
  • GitHub Check: minimal
  • GitHub Check: mypy

Comment on lines +89 to +98
while len(memory_dict) > 0:
memory_dict = {
key: _check_task_output(
task_key=key,
future_obj=value,
cache_directory=cache_dir_dict[key],
)
for key, value in memory_dict.items()
if not value.done()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add timeout and sleep to prevent busy waiting and infinite loops.

The implementation correctly ensures all pending futures complete before shutdown, but the busy-wait loop could consume unnecessary CPU resources and potentially run indefinitely if futures never complete.

Consider adding a timeout mechanism and sleep interval to improve performance and reliability:

+import time
+
 while len(memory_dict) > 0:
+    time.sleep(0.1)  # Add small delay to prevent busy waiting
     memory_dict = {
         key: _check_task_output(
             task_key=key,
             future_obj=value,
             cache_directory=cache_dir_dict[key],
         )
         for key, value in memory_dict.items()
         if not value.done()
     }
+    # Optional: Add timeout to prevent infinite loops
+    # if time.time() - start_time > max_wait_time:
+    #     break

This prevents excessive CPU usage while waiting for futures to complete and provides an escape mechanism for stuck futures.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
while len(memory_dict) > 0:
memory_dict = {
key: _check_task_output(
task_key=key,
future_obj=value,
cache_directory=cache_dir_dict[key],
)
for key, value in memory_dict.items()
if not value.done()
}
import time
while len(memory_dict) > 0:
time.sleep(0.1) # Add small delay to prevent busy waiting
memory_dict = {
key: _check_task_output(
task_key=key,
future_obj=value,
cache_directory=cache_dir_dict[key],
)
for key, value in memory_dict.items()
if not value.done()
}
# Optional: Add timeout to prevent infinite loops
# if time.time() - start_time > max_wait_time:
# break
🤖 Prompt for AI Agents
In executorlib/task_scheduler/file/shared.py around lines 89 to 98, the current
loop busy-waits while checking for incomplete futures, which can cause high CPU
usage and potential infinite loops. To fix this, add a sleep interval inside the
loop to pause briefly between checks, reducing CPU consumption. Additionally,
implement a timeout mechanism that breaks the loop if futures do not complete
within a reasonable time, preventing infinite waiting. Use time tracking to
enforce the timeout and ensure the loop exits gracefully.

@codecov
Copy link

codecov bot commented Jul 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.89%. Comparing base (957170b) to head (5a59a1d).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #712   +/-   ##
=======================================
  Coverage   96.89%   96.89%           
=======================================
  Files          29       29           
  Lines        1320     1322    +2     
=======================================
+ Hits         1279     1281    +2     
  Misses         41       41           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@liamhuber
Copy link
Member

I just check out the branch and tried this on my local machine; for LocalFileExecutor it works with this.

I would still caution that TaskSchedulerBase is not guaranteeing a core promise it should be guaranteeing, but rather relying on sufficiently clever/careful implementation by child classes. But from a functionality perspective, this resolves my problems just fine.

@liamhuber
Copy link
Member

So for all my tests where I use executorlib directly, this and #710 behave the same; however, with #710 I was hung up on one special test case in my integration with pyiron_workflow -- it works fine with this. Given that they are functionally different, I'm happy to swallow my philosophical objections in my last comment and take the solution that solves more of my problems.

@liamhuber
Copy link
Member

Ok, super. On this branch and with pyiron_workflow:executor, I finally manage to get executorlib SLURM execution for individual nodes as easy as wf.n2.executor = (CacheSlurmClusterExecutor, (), {"resource_dict": {"partition": "s.cmfe"}}) (using a with clause and explicitly instantiating it works too, of course). 🚀

Thanks for all the quick fixes and discussion, @jan-janssen

@jan-janssen jan-janssen merged commit b68acc2 into main Jul 12, 2025
52 of 53 checks passed
@jan-janssen jan-janssen deleted the wait_for_future branch July 12, 2025 15:42
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.

[Bug] file-based execution violates futures contract

3 participants