python-utils 4.1.2__py3-none-any.whl → 4.1.4__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.
@@ -72,6 +72,9 @@ async def abatcher(
72
72
  request for it. A source that is an async generator ends at that point.
73
73
  A source with nothing on its way stays usable.
74
74
 
75
+ Items arriving within an interval share its deadline. Waiting for the
76
+ next item does not restart the interval of a nonempty batch.
77
+
75
78
  Args:
76
79
  generator: The async generator or iterator to batch.
77
80
  batch_size (typing.Optional[int], optional): The number of items per
@@ -110,9 +113,13 @@ async def abatcher(
110
113
  # `create_task` insists on a coroutine.
111
114
  pending = {asyncio.ensure_future(generator.__anext__())}
112
115
 
116
+ timeout = interval_s
117
+ if interval and batch:
118
+ timeout = max(0.0, next_yield - time.perf_counter())
119
+
113
120
  done, pending = await asyncio.wait(
114
121
  pending,
115
- timeout=interval_s,
122
+ timeout=timeout,
116
123
  return_when=asyncio.FIRST_COMPLETED,
117
124
  )
118
125
 
@@ -132,7 +139,13 @@ async def abatcher(
132
139
  # next item is flushed on its own once the old one ran out.
133
140
  next_yield = time.perf_counter() + interval_s
134
141
 
135
- if interval and batch and time.perf_counter() > next_yield:
142
+ # A wait that ends without an item ran out of the deadline, so the
143
+ # batch is due. An item that arrives at the deadline joins it.
144
+ if (
145
+ interval
146
+ and batch
147
+ and (not done or time.perf_counter() > next_yield)
148
+ ):
136
149
  yield batch
137
150
  batch = []
138
151
  # Always set the next yield time to the current time. If the
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-utils
3
- Version: 4.1.2
3
+ Version: 4.1.4
4
4
  Summary: Python Utils is a module with some convenient utilities not included with the standard Python install
5
5
  Keywords: utils,utilities,helpers,typing,typed,async,lazy-imports
6
6
  Author: Rick van Hattem
@@ -7,7 +7,7 @@ python_utils/converters.py,sha256=gBOjkVYGwx1aBs7OtjFrMdQgZwI6wbOU_Rvy0u9OVFE,17
7
7
  python_utils/decorators.py,sha256=UyVuV7Phf8kjAt38uA-F9MFH2o8zM4t-fmlgt3KL5cc,8225
8
8
  python_utils/exceptions.py,sha256=B5wljs3Id6eQ9eRaur-ZMPGGmhHNwh9F08Sfw6fuLX4,1230
9
9
  python_utils/formatters.py,sha256=rvbeP7H3h8Hll573PZkWsJPuHETjEHpWleb0tFck8MM,7031
10
- python_utils/generators.py,sha256=5X2mbjkEWl69syOHTxUaQS18ILZ49n2EvXb4cASVjxg,6151
10
+ python_utils/generators.py,sha256=xYGEOzMrdxOmcm2SVMOVUQh9XNzpOpaMD13opzPCp2A,6670
11
11
  python_utils/import_.py,sha256=EnVSLs7Sk1CHrkpiKdXe8i-O6XjS5hXINpjdEohRT4A,5541
12
12
  python_utils/logger.py,sha256=-QuF7Zfo7pxc4nTmAPc9Pm-oz5wsxXIX7NeCnYEPI6I,14043
13
13
  python_utils/loguru.py,sha256=qsap-aXByGXsd4KrYmtneTSUARVIdeVu9xgmrFPtqSI,2696
@@ -15,7 +15,7 @@ python_utils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  python_utils/terminal.py,sha256=GL3n2_rT98LBNmxy-amY-hezGKStCo-9_d_pR-TMgv8,6823
16
16
  python_utils/time.py,sha256=fZz00bpTeLXFFhbAo03LiMLWuzSJU4iPbyGSe7PYshU,16979
17
17
  python_utils/types.py,sha256=N1O2uFE2IuwVJk_vcwz8XNkf-taL-vJ5iNNG6FUXjTg,4336
18
- python_utils-4.1.2.dist-info/licenses/LICENSE,sha256=_Zrs9NZu-G6_aZT2g3Jv5_JREJQfhRNBC61EH6WDH-o,1501
19
- python_utils-4.1.2.dist-info/WHEEL,sha256=xTCBFIZIIyRSxyowOv5Wqg_jFU6KsdIffuulBB09Ph8,80
20
- python_utils-4.1.2.dist-info/METADATA,sha256=3J5FcPBoGz3GUwBqrVVMQ7sCImyan0jHGI3i_2UK-os,15988
21
- python_utils-4.1.2.dist-info/RECORD,,
18
+ python_utils-4.1.4.dist-info/licenses/LICENSE,sha256=_Zrs9NZu-G6_aZT2g3Jv5_JREJQfhRNBC61EH6WDH-o,1501
19
+ python_utils-4.1.4.dist-info/WHEEL,sha256=1dD_GoEqEIxQ7VnrUExgdj_eExY4b4UgfR0iBlGKVac,80
20
+ python_utils-4.1.4.dist-info/METADATA,sha256=rUhxkfT1s7c89-moNYHYWA2FATruk2dZBmXzaimEmi0,15988
21
+ python_utils-4.1.4.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.13.0
2
+ Generator: uv 0.13.4
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any