Raise runtime error when submitting after executor shutdown#851
Raise runtime error when submitting after executor shutdown#851jan-janssen merged 2 commits intomainfrom
Conversation
WalkthroughThis PR introduces a shutdown guard mechanism to the BaseExecutor class. An internal Changes
Sequence DiagramsequenceDiagram
participant Client
participant Executor
participant TaskScheduler
Client->>Executor: submit(task)
alt _is_active == True
Executor->>TaskScheduler: schedule task
TaskScheduler-->>Executor: ✓
Executor-->>Client: future
else _is_active == False
Executor-->>Client: ✗ RuntimeError
end
Client->>Executor: shutdown()
Executor->>TaskScheduler: shutdown
Executor->>Executor: _is_active = False
TaskScheduler-->>Executor: ✓
Client->>Executor: submit(task)
Executor-->>Client: ✗ RuntimeError (guarded)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/executorlib/executor/base.py (1)
103-108: Good shutdown guard implementation; consider unpacking syntax.The logic correctly prevents submissions after shutdown and provides a clear error message.
Consider using the unpacking syntax as suggested by static analysis:
if self._is_active: return self._task_scheduler.submit( - *([fn] + list(args)), resource_dict=resource_dict, **kwargs + fn, *args, resource_dict=resource_dict, **kwargs )This is more idiomatic and avoids the list concatenation and unpacking overhead. Based on learnings
tests/test_singlenodeexecutor_noblock.py (1)
170-175: Good test coverage for explicit shutdown; consider testing context manager exit.The test correctly validates that submissions are blocked after calling
shutdown().Consider adding a complementary test for the context manager exit path:
def test_single_node_executor_context_manager_exit(self): with SingleNodeExecutor(max_workers=2) as exe: self.assertEqual(exe.submit(sum, [1, 2, 3]).result(), 6) # After exiting context manager with self.assertRaises(RuntimeError): exe.submit(sum, [1, 2, 3])This would verify that the shutdown guard also works when the executor exits via
__exit__.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/executorlib/executor/base.py(4 hunks)tests/test_singlenodeexecutor_noblock.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/test_singlenodeexecutor_noblock.py (1)
src/executorlib/executor/base.py (4)
max_workers(27-28)max_workers(31-32)submit(71-108)shutdown(110-126)
src/executorlib/executor/base.py (3)
src/executorlib/task_scheduler/base.py (1)
submit(89-144)src/executorlib/task_scheduler/interactive/blockallocation.py (1)
submit(123-160)src/executorlib/task_scheduler/interactive/dependency.py (1)
submit(113-153)
🪛 Ruff (0.14.1)
src/executorlib/executor/base.py
105-105: Consider [fn, *list(args)] instead of concatenation
Replace with [fn, *list(args)]
(RUF005)
108-108: Avoid specifying long messages outside the exception class
(TRY003)
🔇 Additional comments (3)
src/executorlib/executor/base.py (3)
24-24: LGTM! Clean initialization of the shutdown guard.The
_is_activeflag is properly initialized to allow submissions until shutdown.
125-126: LGTM! Proper flag update after shutdown.The
_is_activeflag is correctly set to False after the task scheduler shutdown completes.
150-151: LGTM! Context manager exit properly handled.The
_is_activeflag is correctly set to False after the context manager exit, ensuring the shutdown guard works withwithstatements.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #851 +/- ##
==========================================
+ Coverage 93.24% 93.26% +0.01%
==========================================
Files 38 38
Lines 1791 1796 +5
==========================================
+ Hits 1670 1675 +5
Misses 121 121 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary by CodeRabbit