Skip to content
Merged
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
19 changes: 19 additions & 0 deletions src/_pytask/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
from _pytask.session import Session


_LIVE_DISPLAY_OWNER: LiveManager | None = None


@hookimpl
def pytask_extend_command_line_interface(cli: click.Group) -> None:
"""Extend command line interface."""
Expand Down Expand Up @@ -110,6 +113,18 @@ class LiveManager:
)

def start(self) -> None:
global _LIVE_DISPLAY_OWNER # noqa: PLW0603
if _LIVE_DISPLAY_OWNER is not None and _LIVE_DISPLAY_OWNER is not self:
msg = (
"pytask tried to launch a second live display which is impossible. The "
"issue occurs when you use pytask on the command line on a task module "
"that uses the programmatic interface of pytask at the same time. "
"Use either the command line or the programmatic interface."
)
raise Exit(msg)
if self._live.is_started:
_LIVE_DISPLAY_OWNER = self
return
try:
self._live.start()
except LiveError:
Expand All @@ -120,11 +135,15 @@ def start(self) -> None:
"Use either the command line or the programmatic interface."
)
raise Exit(msg) from None
_LIVE_DISPLAY_OWNER = self

def stop(self, transient: bool | None = None) -> None:
global _LIVE_DISPLAY_OWNER # noqa: PLW0603
if transient is not None:
self._live.transient = transient
self._live.stop()
if _LIVE_DISPLAY_OWNER is self:
_LIVE_DISPLAY_OWNER = None

def pause(self) -> None:
self._live.transient = True
Expand Down