-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add submit_taskgraph for a common UX #641
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import sys | ||
from concurrent.futures import ThreadPoolExecutor | ||
from concurrent.futures import wait | ||
from concurrent.futures._base import TimeoutError | ||
from fnmatch import fnmatch | ||
from typing import ( | ||
Any, | ||
|
@@ -195,6 +196,74 @@ def run_dag( | |
_print_logs(graph, debug=debug) | ||
|
||
|
||
def submit_taskgraph( | ||
graph: dag.DAG, | ||
*, | ||
wait: bool = True, | ||
update_sec: int = 10, | ||
) -> Mapping[str, str]: | ||
""" | ||
Submit a taskgraph and optionally wait for completion. | ||
|
||
:param graph: taskgraph to submit | ||
:param wait: wait for the taskgraph to complete, defaults to True | ||
:param update_sec: interval in seconds to update the progress bar, defaults to 10 | ||
:return: dictionary with status and graph_id | ||
""" | ||
|
||
# Try to import tqdm, if not available, stub it out | ||
try: | ||
from tqdm import tqdm | ||
except ImportError: | ||
|
||
class tqdm: | ||
def __init__(self, *args, **kwargs): | ||
print("Please install tqdm to display a progress timer.") | ||
|
||
def set_description_str(self, *args, **kwargs): | ||
pass | ||
|
||
graph.compute() | ||
|
||
# Display a link to the log in TileDB, if available | ||
if graph.server_graph_uuid: | ||
print( | ||
f"Taskgraph submitted to TileDB - https://cloud.tiledb.com/activity/taskgraphs/{graph.namespace}/{graph.server_graph_uuid}", | ||
) | ||
|
||
if wait: | ||
# Display the progress bar in stdout, so the output is not red in a notebook | ||
pbar = tqdm( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, I think a progress bar should be explicitly opt-in and not conditioned on waiting. I can easily imagine wanting to waiting silently. How about |
||
desc="Not Started", | ||
bar_format="{desc}: {elapsed} (min:sec)", | ||
file=sys.stdout, | ||
) | ||
cancelled = False | ||
|
||
while True: | ||
try: | ||
graph.wait(update_sec) | ||
except TimeoutError: | ||
# Still running | ||
pbar.set_description_str(str(graph.status)) | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused about what |
||
except RuntimeError as e: | ||
if "No executions found for done Node" in str(e): | ||
cancelled = True | ||
except StopIteration: | ||
cancelled = True | ||
|
||
if cancelled: | ||
pbar.set_description("Cancelled") | ||
return {"status": "Cancelled", "graph_id": str(graph.server_graph_uuid)} | ||
|
||
# The taskgraph is done, break the loop | ||
pbar.set_description_str(str(graph.status)) | ||
break | ||
|
||
return {"status": str(graph.status), "graph_id": str(graph.server_graph_uuid)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more natural for a Python function to return a tuple, no? More like standard lib functions is what i mean. |
||
|
||
|
||
def _print_logs( | ||
graph: dag.DAG, | ||
*, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's opt in to printing. I don't think a library function should print by default. I can't think of anything in Python's standard lib that prints except
print()
.Like
if verbose and graph.server_graph_uuid: