Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Raalsky committed Nov 21, 2023
1 parent e92efee commit ff82d11
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ pattern = "default-unprefixed"
python = "^3.7"

# Base neptune package
# TODO: Change to "^1.8.4" when released
neptune = "^1.8.3"
neptune = "^1.8.5"

# For 3.7 compatibility
typing_extensions = "^4.0.0"
Expand Down
13 changes: 7 additions & 6 deletions src/neptune_experimental/remote_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@
TYPE_CHECKING,
Any,
Callable,
List,
)

from neptune_experimental.utils import wrap_method

if TYPE_CHECKING:
from neptune import Run
from neptune.internal.backgroud_job_list import BackgroundJobList
from neptune.internal.background_job import BackgroundJob


def initialize() -> None:
from neptune import Run

# Monkey patching
wrap_method(obj=Run, method="__init__", wrapper=init_with_enable_remote_signals)
wrap_method(obj=Run, method="_prepare_background_jobs", wrapper=prepare_background_jobs)
wrap_method(obj=Run, method="_get_background_jobs", wrapper=get_background_jobs)


def init_with_enable_remote_signals(self: "Run", *args: Any, original: Callable[..., Any], **kwargs: Any) -> None:
Expand All @@ -51,17 +52,17 @@ def init_with_enable_remote_signals(self: "Run", *args: Any, original: Callable[
original(self, *args, **kwargs)


def prepare_background_jobs(self: "Run", original: Callable[..., Any]) -> "BackgroundJobList":
def get_background_jobs(self: "Run", original: Callable[..., Any]) -> List["BackgroundJob"]:
from neptune.internal.websockets.websocket_signals_background_job import WebsocketSignalsBackgroundJob

background_jobs = original(self)
background_jobs: List["BackgroundJob"] = original(self)

if not self._enable_remote_signals:
# filter-out websocket job
background_jobs._jobs = list(
background_jobs = list(
filter(
lambda x: not isinstance(x, WebsocketSignalsBackgroundJob),
background_jobs._jobs,
background_jobs,
)
)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_remote_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
def test_disabled_remote_signals():
with Run(mode="debug", enable_remote_signals=False) as run:
assert run._enable_remote_signals is False
jobs = run._prepare_background_jobs()._jobs
jobs = run._get_background_jobs()
assert not [job for job in jobs if isinstance(job, WebsocketSignalsBackgroundJob)]

0 comments on commit ff82d11

Please sign in to comment.