Skip to content

Commit 97ef231

Browse files
authored
Fix boolean evaluation (#664)
* Remove queue length function * Always return bool
1 parent 49d2126 commit 97ef231

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

executorlib/executor/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ def __len__(self) -> int:
112112
"""
113113
return len(self._task_scheduler)
114114

115+
def __bool__(self):
116+
"""
117+
Overwrite length to always return True
118+
119+
Returns:
120+
bool: Always return True
121+
"""
122+
return True
123+
115124
def __exit__(self, *args, **kwargs) -> None:
116125
"""
117126
Exit method called when exiting the context manager.

tests/test_integration_pyiron_workflow.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def slowly_returns_dynamic(dynamic_arg):
7676

7777
dynamic_dynamic = slowly_returns_dynamic()
7878
executor = SingleNodeExecutor(block_allocation=True, max_workers=1)
79+
self.assertTrue(executor)
7980
cloudpickle_register(ind=1)
8081
dynamic_object = does_nothing()
8182
fs = executor.submit(dynamic_dynamic.run, dynamic_object)
@@ -106,6 +107,7 @@ def slowly_returns_42():
106107
dynamic_42.result, msg="Just a sanity check that the test is set up right"
107108
)
108109
executor = SingleNodeExecutor(block_allocation=True, max_workers=1)
110+
self.assertTrue(executor)
109111
cloudpickle_register(ind=1)
110112
fs = executor.submit(dynamic_42.run)
111113
fs.add_done_callback(dynamic_42.process_result)
@@ -137,6 +139,7 @@ def returns_42():
137139
msg="Sanity check that the test starts in the expected condition",
138140
)
139141
executor = SingleNodeExecutor(block_allocation=True, max_workers=1)
142+
self.assertTrue(executor)
140143
cloudpickle_register(ind=1)
141144
fs = executor.submit(dynamic_42.run)
142145
fs.add_done_callback(dynamic_42.process_result)
@@ -161,6 +164,7 @@ def raise_error():
161164

162165
re = raise_error()
163166
executor = SingleNodeExecutor(block_allocation=True, max_workers=1)
167+
self.assertTrue(executor)
164168
cloudpickle_register(ind=1)
165169
fs = executor.submit(re.run)
166170
with self.assertRaises(
@@ -191,6 +195,7 @@ def slowly_returns_dynamic():
191195

192196
dynamic_dynamic = slowly_returns_dynamic()
193197
executor = SingleNodeExecutor(block_allocation=True, max_workers=1)
198+
self.assertTrue(executor)
194199
cloudpickle_register(ind=1)
195200
fs = executor.submit(dynamic_dynamic.run)
196201
self.assertIsInstance(
@@ -220,6 +225,7 @@ def slow():
220225

221226
f = slow()
222227
executor = SingleNodeExecutor(block_allocation=True, max_workers=1)
228+
self.assertTrue(executor)
223229
cloudpickle_register(ind=1)
224230
fs = executor.submit(f.run)
225231
self.assertEqual(

tests/test_singlenodeexecutor_cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class TestCacheFunctions(unittest.TestCase):
2424
def test_cache_data(self):
2525
cache_directory = "./cache"
2626
with SingleNodeExecutor(cache_directory=cache_directory) as exe:
27+
self.assertTrue(exe)
2728
future_lst = [exe.submit(sum, [i, i]) for i in range(1, 4)]
2829
result_lst = [f.result() for f in future_lst]
2930

@@ -36,6 +37,7 @@ def test_cache_data(self):
3637
def test_cache_error(self):
3738
cache_directory = "./cache_error"
3839
with SingleNodeExecutor(cache_directory=cache_directory) as exe:
40+
self.assertTrue(exe)
3941
cloudpickle_register(ind=1)
4042
f = exe.submit(get_error, a=1)
4143
with self.assertRaises(ValueError):

0 commit comments

Comments
 (0)