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: Run _async_no_progress_callback and _async_lag_callback in new t… #1521

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _check_lag(self) -> None:

Raalsky marked this conversation as resolved.
Show resolved Hide resolved
with self._lock:
if not self._lag_exceeded:
self._async_lag_callback()
threading.Thread(target=self._async_lag_callback, daemon=True).start()
self._lag_exceeded = True

def _check_no_progress(self) -> None:
Expand All @@ -162,7 +162,7 @@ def _check_no_progress(self) -> None:

with self._lock:
if self._should_call_no_progress_callback:
self._async_no_progress_callback()
threading.Thread(target=self._async_no_progress_callback, daemon=True).start()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

daemon=True False?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that Python doesn't require to call join()? I heard that sometimes it may be needed (it wasn't Python). Stackoverflow says it's fine: https://stackoverflow.com/questions/49912013/python-what-if-we-call-thread-start-and-leave-it-without-join-or-close but just to be sure 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With join the caller will wait and hold the lock indefinitely.

Copy link
Contributor Author

@PatrykGala PatrykGala Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All background jobs have daemon=True, and I think that callbacks shouldn't block the exit of program.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All background jobs have daemon=True, and I think that callbacks shouldn't block the exit of program.

We should probably ask someone from Product Team here :<

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With join the caller will wait and hold the lock indefinitely.

Yeah, I know. I was thinking about joining at the end of a script but I've looked for something like that and it's fine that we're not calling join at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But let's proceed with this fix. This could be changed anytime.

self._should_call_no_progress_callback = False

def _wait_for_queue_empty(self, initial_queue_size: int, seconds: Optional[float]) -> None:
Expand Down
5 changes: 3 additions & 2 deletions src/neptune/internal/threading/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import abc
import functools
import threading
import time
from enum import Enum

from neptune.common.exceptions import NeptuneConnectionLostException
Expand Down Expand Up @@ -133,7 +132,9 @@ def wrapper(self_: Daemon, *args, **kwargs):
self_.last_backoff_time = self.INITIAL_RETRY_BACKOFF
else:
self_.last_backoff_time = min(self_.last_backoff_time * 2, self.MAX_RETRY_BACKOFF)
time.sleep(self_.last_backoff_time)

with self_._wait_condition:
self_._wait_condition.wait(self_.last_backoff_time)
except Exception:
logger.error(
"Unexpected error occurred in Neptune background thread: %s",
Expand Down