You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-2Lines changed: 12 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -305,12 +305,21 @@ If you wish to avoid excessive throttling or have multiple producers on a stream
305
305
```python
306
306
from kinesis import Consumer
307
307
308
+
# One-shot: consume until idle_timeout (default 2s) with no new records
308
309
asyncwith Consumer(stream_name="test") as consumer:
309
310
asyncfor item in consumer:
310
311
print(item)
311
-
# Consumer continues to wait for new messages after catching up
312
+
313
+
# Continuous: wrap in while True to keep consuming across idle gaps
314
+
asyncwith Consumer(stream_name="test") as consumer:
315
+
whileTrue:
316
+
asyncfor item in consumer:
317
+
print(item)
312
318
```
313
319
320
+
> **Note**: `async for` ends after `idle_timeout` seconds of queue inactivity (default 2.0s).
321
+
> For continuous consumption, wrap the `async for` in a `while True` loop.
322
+
314
323
315
324
Options:
316
325
@@ -324,7 +333,7 @@ Options:
324
333
| max_queue_size | 10000 | the fetch() task shard will block when queue is at max |
325
334
| max_shard_consumers | None | Max number of shards to use. None = all |
326
335
| record_limit | 10000 | Number of records to fetch with get_records() |
327
-
| sleep_time_no_records | 2 |No of seconds to sleep when caught up|
336
+
| sleep_time_no_records | 2 |Seconds to sleep per shard when no new records are returned by `get_records`|
328
337
| iterator_type | TRIM_HORIZON | Default shard iterator type for new/unknown shards (ie start from start of stream). Alternatives are "LATEST" (ie end of stream), "AT_TIMESTAMP" (ie particular point in time, requires defining `timestamp` arg) |
329
338
| shard_fetch_rate | 1 | No of fetches per second (max = 5). 1 is recommended as allows having multiple consumers without hitting the max limit. |
330
339
| checkpointer | MemoryCheckPointer() | Checkpointer to use |
@@ -337,6 +346,7 @@ Options:
337
346
| create_stream | False | Creates a Kinesis Stream based on the `stream_name` keyword argument. Note if stream already existing it will ignore |
338
347
| create_stream_shards | 1 | Sets the amount of shard you want for your new stream. Note if stream already existing it will ignore |
339
348
| describe_timeout | 60 | Timeout in seconds for waiting for stream to become ACTIVE during startup. Increase for slow backends (e.g. LocalStack) |
349
+
| idle_timeout | 2.0 | Seconds to wait for new records before ending iteration. Controls how long `async for` blocks on an empty queue before raising `StopAsyncIteration`|
340
350
| timestamp | None | Timestamp to start reading stream from. Used with iterator type "AT_TIMESTAMP"
0 commit comments