Skip to content

Commit 3f3f212

Browse files
jan-janssenpre-commit-ci[bot]coderabbitai[bot]
authored
Fix info (#590)
* Fix info * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix type check * Update tests/test_dependencies_executor.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Update test_dependencies_executor.py * Update dependency.py * Update dependency.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 00366ad commit 3f3f212

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

executorlib/interactive/dependency.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ def __init__(
6565
else:
6666
self._generate_dependency_graph = True
6767

68+
@property
69+
def info(self) -> Optional[dict]:
70+
"""
71+
Get the information about the executor.
72+
73+
Returns:
74+
Optional[dict]: Information about the executor.
75+
"""
76+
if isinstance(self._future_queue, queue.Queue):
77+
f: Future = Future()
78+
self._future_queue.queue.insert(
79+
0, {"internal": True, "task": "info", "future": f}
80+
)
81+
return f.result()
82+
else:
83+
return None
84+
6885
def submit( # type: ignore
6986
self,
7087
fn: Callable[..., Any],
@@ -168,6 +185,11 @@ def _execute_tasks_with_dependencies(
168185
future_queue.task_done()
169186
future_queue.join()
170187
break
188+
if ( # shutdown the executor
189+
task_dict is not None and "internal" in task_dict and task_dict["internal"]
190+
):
191+
if task_dict["task"] == "info":
192+
task_dict["future"].set_result(executor.info)
171193
elif ( # handle function submitted to the executor
172194
task_dict is not None and "fn" in task_dict and "future" in task_dict
173195
):

tests/test_dependencies_executor.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from executorlib.interfaces.single import create_single_node_executor
99
from executorlib.interactive.dependency import _execute_tasks_with_dependencies
1010
from executorlib.standalone.serialize import cloudpickle_register
11+
from executorlib.standalone.interactive.spawner import MpiExecSpawner
1112

1213

1314
try:
@@ -327,3 +328,36 @@ def test_block_allocation_true_two_workers_loop(self):
327328
parameter=lst,
328329
)
329330
lst.result()
331+
332+
333+
class TestInfo(unittest.TestCase):
334+
"""Test cases for the info property of SingleNodeExecutor."""
335+
336+
def setUp(self):
337+
"""Set up the expected info dictionary."""
338+
self.expected_info = {
339+
'cores': 1,
340+
'cwd': None,
341+
'openmpi_oversubscribe': False,
342+
'cache_directory': None,
343+
'hostname_localhost': None,
344+
'spawner': MpiExecSpawner,
345+
'max_cores': None,
346+
'max_workers': None,
347+
}
348+
349+
def test_info_disable_dependencies_true(self):
350+
"""Test info property with dependencies disabled."""
351+
with SingleNodeExecutor(disable_dependencies=True) as exe:
352+
self.assertEqual(exe.info, self.expected_info)
353+
354+
def test_info_disable_dependencies_false(self):
355+
"""Test info property with dependencies enabled."""
356+
with SingleNodeExecutor(disable_dependencies=False) as exe:
357+
self.assertEqual(exe.info, self.expected_info)
358+
359+
def test_info_error_handling(self):
360+
"""Test info property error handling when executor is not running."""
361+
exe = SingleNodeExecutor()
362+
exe.shutdown(wait=True)
363+
self.assertIsNone(exe.info)

0 commit comments

Comments
 (0)