Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 20, 2024
1 parent aeae8f8 commit 0249b4a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/tqdm_publisher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ._publisher import TQDMPublisher
from ._progress_subscriber import TQDMProgressSubscriber
from ._progress_handler import TQDMProgressHandler
from ._progress_subscriber import TQDMProgressSubscriber
from ._publisher import TQDMPublisher

__all__ = ["TQDMPublisher", "TQDMProgressSubscriber", "TQDMProgressHandler"]
15 changes: 9 additions & 6 deletions src/tqdm_publisher/_progress_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import queue

from ._progress_subscriber import TQDMProgressSubscriber


class TQDMProgressHandler:
def __init__(self):
self.listeners = []
Expand All @@ -9,16 +11,17 @@ def listen(self):
q = queue.Queue(maxsize=25)
self.listeners.append(q)
return q

def create(self, iterable, additional_metadata: dict = dict(), **tqdm_kwargs):
return TQDMProgressSubscriber(iterable, lambda progress_update: self._announce(dict(
**progress_update,
**additional_metadata
)), **tqdm_kwargs)
return TQDMProgressSubscriber(
iterable,
lambda progress_update: self._announce(dict(**progress_update, **additional_metadata)),
**tqdm_kwargs,
)

def _announce(self, msg):
for i in reversed(range(len(self.listeners))):
try:
self.listeners[i].put_nowait(msg)
except queue.Full:
del self.listeners[i]
del self.listeners[i]
3 changes: 2 additions & 1 deletion src/tqdm_publisher/_progress_subscriber.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ._publisher import TQDMPublisher


class TQDMProgressSubscriber(TQDMPublisher):
def __init__(self, iterable, on_progress_update: callable, **tqdm_kwargs):
super().__init__(iterable, **tqdm_kwargs)
self.subscribe(lambda format_dict: on_progress_update(dict(progress_bar_id=self.id, format_dict=format_dict)))
self.subscribe(lambda format_dict: on_progress_update(dict(progress_bar_id=self.id, format_dict=format_dict)))

0 comments on commit 0249b4a

Please sign in to comment.