Skip to content
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

Fix issue with global output manager tree #2062

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions modal/_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def finalize(self):

class OutputManager:
_instance: ClassVar[Optional["OutputManager"]] = None
_tree: ClassVar[Optional[Tree]] = None

_console: Console
_task_states: Dict[str, int]
Expand All @@ -168,6 +167,7 @@ class OutputManager:
_app_page_url: Optional[str]
_show_image_logs: bool
_status_spinner_live: Optional[Live]
_tree: Optional[Tree]

def __init__(
self,
Expand All @@ -188,6 +188,7 @@ def __init__(
self._app_page_url = None
self._show_image_logs = False
self._status_spinner_live = None
self._tree = None

@classmethod
def disable(cls):
Expand Down Expand Up @@ -389,23 +390,26 @@ def show_status_spinner(self):
@classmethod
@contextlib.contextmanager
def make_tree(cls):
# Note: If the output isn't enabled, don't actually show the tree.
cls._tree = Tree(step_progress("Creating objects..."), guide_style="gray50")

if output_mgr := OutputManager.get():
with output_mgr.make_live(cls._tree):
yield
cls._tree.label = step_completed("Created objects.")
output_mgr.print(output_mgr._tree)
tree = output_mgr._tree = Tree(step_progress("Creating objects..."), guide_style="gray50")
with output_mgr.make_live(tree):
try:
yield
finally:
output_mgr._tree = None
tree.label = step_completed("Created objects.")
output_mgr.print(tree)
else:
yield

@classmethod
def add_status_row(cls) -> "StatusRow":
# Return a status row to be used for object creation.
# If output isn't enabled, the status row might be invisible.
assert cls._tree, "Output manager has no tree yet"
return StatusRow(cls._tree)
# If output isn't enabled, just create a hidden tree
if cls._instance and cls._instance._tree:
return StatusRow(cls._instance._tree)
else:
return StatusRow(Tree(""))


class ProgressHandler:
Expand Down
6 changes: 6 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import modal._serialization
from modal import __version__, config
from modal._container_io_manager import _ContainerIOManager
from modal._output import OutputManager
from modal._serialization import serialize_data_format
from modal._utils.async_utils import asyncify, synchronize_api
from modal._utils.grpc_testing import patch_mock_servicer
Expand Down Expand Up @@ -1551,6 +1552,11 @@ async def reset_default_client():
Client.set_env_client(None)


@pytest_asyncio.fixture(scope="function", autouse=True)
async def reset_output_manager():
OutputManager._instance = None


@pytest.fixture(name="mock_dir", scope="session")
def mock_dir_factory():
"""Sets up a temp dir with content as specified in a nested dict
Expand Down
Loading