dycw-utilities 0.125.23__py3-none-any.whl → 0.125.24__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.125.23
3
+ Version: 0.125.24
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,6 +1,6 @@
1
- utilities/__init__.py,sha256=wPKNBX6ygqFYs-IuHSilaZXm0vMIdcuqBGP9j1b_5O8,61
1
+ utilities/__init__.py,sha256=WpvBRRRg9E0dopLOUcZu11h6cdS3FNrVVkS3L8r2LCU,61
2
2
  utilities/altair.py,sha256=Gpja-flOo-Db0PIPJLJsgzAlXWoKUjPU1qY-DQ829ek,9156
3
- utilities/asyncio.py,sha256=wtMOjHG85exqdwVBNH-DazTprkUCvMFv-JgY-9REhYs,51259
3
+ utilities/asyncio.py,sha256=qdhfPAKgeJEOKDN2xQbR35dpvYZSWUUqLhHNJEd-pv0,51733
4
4
  utilities/atomicwrites.py,sha256=geFjn9Pwn-tTrtoGjDDxWli9NqbYfy3gGL6ZBctiqSo,5393
5
5
  utilities/atools.py,sha256=IYMuFSFGSKyuQmqD6v5IUtDlz8PPw0Sr87Cub_gRU3M,1168
6
6
  utilities/cachetools.py,sha256=C1zqOg7BYz0IfQFK8e3qaDDgEZxDpo47F15RTfJM37Q,2910
@@ -90,7 +90,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
90
90
  utilities/whenever.py,sha256=jS31ZAY5OMxFxLja_Yo5Fidi87Pd-GoVZ7Vi_teqVDA,16743
91
91
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
92
92
  utilities/zoneinfo.py,sha256=-5j7IQ9nb7gR43rdgA7ms05im-XuqhAk9EJnQBXxCoQ,1874
93
- dycw_utilities-0.125.23.dist-info/METADATA,sha256=sTzpB8MuDKbN3vHMg9otGuFDqzQ6Ko-_iYSb_9W94QY,12852
94
- dycw_utilities-0.125.23.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
95
- dycw_utilities-0.125.23.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
96
- dycw_utilities-0.125.23.dist-info/RECORD,,
93
+ dycw_utilities-0.125.24.dist-info/METADATA,sha256=PTMh4H329ZNF8vQUXJ4Z62OIxQ_NrfmL2jBxEhjvuS0,12852
94
+ dycw_utilities-0.125.24.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
95
+ dycw_utilities-0.125.24.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
96
+ dycw_utilities-0.125.24.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.125.23"
3
+ __version__ = "0.125.24"
utilities/asyncio.py CHANGED
@@ -688,6 +688,7 @@ class Looper(Generic[_T]):
688
688
  auto_start: bool = field(default=False, repr=False)
689
689
  freq: Duration = field(default=SECOND, repr=False)
690
690
  backoff: Duration = field(default=10 * SECOND, repr=False)
691
+ empty_upon_exit: bool = field(default=False, repr=False)
691
692
  logger: str | None = field(default=None, repr=False)
692
693
  timeout: Duration | None = field(default=None, repr=False)
693
694
  timeout_error: type[Exception] = field(default=LooperTimeoutError, repr=False)
@@ -791,6 +792,8 @@ class Looper(Generic[_T]):
791
792
  )
792
793
  _ = await self._stack.__aexit__(exc_type, exc_value, traceback)
793
794
  await self.stop()
795
+ if self.empty_upon_exit:
796
+ await self.run_until_empty()
794
797
  case False:
795
798
  _ = self._debug and self._logger.debug("%s: already exited", self)
796
799
  case _ as never:
@@ -891,6 +894,7 @@ class Looper(Generic[_T]):
891
894
  self,
892
895
  *,
893
896
  auto_start: bool | Sentinel = sentinel,
897
+ empty_upon_exit: bool | Sentinel = sentinel,
894
898
  freq: Duration | Sentinel = sentinel,
895
899
  backoff: Duration | Sentinel = sentinel,
896
900
  logger: str | None | Sentinel = sentinel,
@@ -902,6 +906,7 @@ class Looper(Generic[_T]):
902
906
  return replace_non_sentinel(
903
907
  self,
904
908
  auto_start=auto_start,
909
+ empty_upon_exit=empty_upon_exit,
905
910
  freq=freq,
906
911
  backoff=backoff,
907
912
  logger=logger,
@@ -1061,6 +1066,13 @@ class Looper(Generic[_T]):
1061
1066
  self._core_successes += 1
1062
1067
  await sleep(self._freq)
1063
1068
 
1069
+ async def run_until_empty(self) -> None:
1070
+ """Run until the queue is empty."""
1071
+ while not self.empty():
1072
+ await self.core()
1073
+ if not self.empty():
1074
+ await sleep(self._freq)
1075
+
1064
1076
  @property
1065
1077
  def stats(self) -> _LooperStats:
1066
1078
  """Return the statistics."""