Repository: scalableminds/cluster_tools

Issue:
map_to_futures with empty list crashes, should return empty list
The resumable executor of voxelytics checks what needs to be re-run. If that list becomes empty, map_to_futures crashes

Discussion:

Patch:
diff --git a/cluster_tools/schedulers/cluster_executor.py b/cluster_tools/schedulers/cluster_executor.py
index 68d4cd1..304588a 100644
--- a/cluster_tools/schedulers/cluster_executor.py
+++ b/cluster_tools/schedulers/cluster_executor.py
@@ -10,9 +10,7 @@ import time
 from abc import abstractmethod
 import logging
 from typing import Union
-from ..util import local_filename
 from cluster_tools.tailf import Tail
-from logging import getLogger
 
 class RemoteException(Exception):
     def __init__(self, error, job_id):
@@ -249,6 +247,9 @@ class ClusterExecutor(futures.Executor):
     def map_to_futures(self, fun, allArgs, output_pickle_path_getter=None):
         self.ensure_not_shutdown()
         allArgs = list(allArgs)
+        if len(allArgs) == 0:
+            return []
+
         should_keep_output = output_pickle_path_getter is not None
 
         futs_with_output_paths = []


Test patch:
diff --git a/test.py b/test.py
index 0eb4662..05c00d3 100644
--- a/test.py
+++ b/test.py
@@ -1,8 +1,6 @@
 import cluster_tools
-import subprocess
 import concurrent.futures
 import time
-import sys
 import logging
 from enum import Enum
 from functools import partial
@@ -163,6 +161,12 @@ def test_map_to_futures():
             for duration, result in zip(durations, results):
                 assert result == duration
 
+def test_empty_map_to_futures():
+    for exc in get_executors():
+        with exc:
+            futures = exc.map_to_futures(sleep, [])
+            results = [f.result() for f in futures]
+            assert len(results) == 0
 
 def output_pickle_path_getter(tmp_dir, chunk):
 
@@ -170,8 +174,6 @@ def output_pickle_path_getter(tmp_dir, chunk):
 
 def test_map_to_futures_with_pickle_paths():
 
-    dir_path = Path("").resolve()
-
     for exc in get_executors():
         with tempfile.TemporaryDirectory(dir=".") as tmp_dir:
             with exc: