-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
@jan-janssen Here is a mockup of how I was planning to use executorlib in the amorphouspy API [1]
Note that this currently fails - f2 is never done()
"""Reproduce submit/check pattern: submit with one executor, check with another."""
import tempfile
import time
from pathlib import Path
# doesn't matter whether we use TestClusterExecutor or SingleNodeExecutor
# from executorlib.api import TestClusterExecutor as MyExecutor
from executorlib import SingleNodeExecutor as MyExecutor
def slow_add(a, b):
time.sleep(4)
return a + b
if __name__ == "__main__":
with tempfile.TemporaryDirectory() as tmpdir:
cache_dir = Path(tmpdir) / "jobs"
# Submit
exe = MyExecutor(cache_directory=cache_dir)
future = exe.submit(slow_add, 2, 3)
exe.shutdown(wait=False, cancel_futures=False)
print(f"submitted, done={future.done()}")
# Poll with new executor every 2s
for i in range(10):
time.sleep(2)
exe2 = MyExecutor(cache_directory=cache_dir)
f2 = exe2.submit(slow_add, 2, 3)
exe2.shutdown(wait=False, cancel_futures=False)
print(f"poll {i+1}: done={f2.done()}")
if f2.done():
print(f"result={f2.result()}")
break
else:
print("TIMEOUT")[1] This is a slight simplification since in the API the submit and poll stages run in separate threads.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested