stream2py 1.0.46__tar.gz → 1.0.47__tar.gz
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.
- {stream2py-1.0.46 → stream2py-1.0.47}/PKG-INFO +1 -1
- {stream2py-1.0.46 → stream2py-1.0.47}/pyproject.toml +1 -1
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/buffer_reader.py +11 -1
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_buffer_reader_blocking.py +14 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/.gitattributes +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/.github/workflows/ci.yml +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/.gitignore +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/ISSUE_ANALYSIS.md +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/ISSUE_COMMENTS.md +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/LICENSE +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/PR_DESCRIPTION.md +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/README.md +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/README.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/RESOLVED_ISSUES.md +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/.gitignore +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/Makefile +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/conf.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/index.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/make.bat +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/buffer_reader.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/protocols.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/simply.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/source_reader.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/sources/http.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/sources.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/stream_buffer.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/stream_source.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_buffer_reader.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_lock_sorted_deque.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_source_reader.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_stream_buffer.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_stream_source.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_util.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/utils_for_testing.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/util.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/utility/locked_sorted_deque.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/utility/reader_writer_lock.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/utility/sorted_collection.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/utility/sorted_deque.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/utility/typing_hints.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/docsrc/table_of_contents.rst +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/pack.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/__init__.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/examples/source_reader.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/examples/stream_source.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/exceptions.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/protocols.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/simply.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/source_reader.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/sources/__init__.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/sources/http.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/stream_buffer.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/stream_source.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/__init__.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_buffer_reader.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_buffer_reader_stopiteration.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_lock_sorted_deque.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_quick_source_reader.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_reader_without_context.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_source_reader.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_stream_buffer.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_stream_source.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_util.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/test_zz_range_join.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/tests/utils_for_testing.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/util.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/utility/__init__.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/utility/locked_sorted_deque.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/utility/reader_writer_lock.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/utility/sorted_collection.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/utility/sorted_deque.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/stream2py/utility/typing_hints.py +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/things_you_can_do.md +0 -0
- {stream2py-1.0.46 → stream2py-1.0.47}/use_cases.md +0 -0
|
@@ -389,6 +389,7 @@ class BufferReader:
|
|
|
389
389
|
ignore_no_item_found=None,
|
|
390
390
|
strict_n=None,
|
|
391
391
|
blocking=False,
|
|
392
|
+
timeout=None,
|
|
392
393
|
):
|
|
393
394
|
"""Finds an item with a key greater than the last returned item.
|
|
394
395
|
Raise ValueError if no item found with key above last item.
|
|
@@ -402,6 +403,9 @@ class BufferReader:
|
|
|
402
403
|
instead of raising exception
|
|
403
404
|
:param strict_n: if True, raise ValueError if n items are not available
|
|
404
405
|
:param blocking: if True, wait to return next item if not yet available
|
|
406
|
+
:param timeout: only used when ``blocking`` is True. Maximum number of seconds
|
|
407
|
+
to wait; ``None`` (default) waits until an item is available or the stream
|
|
408
|
+
stops. When it runs out, returns None (as when the stream stops).
|
|
405
409
|
:return: next item or list of next items if n > 1
|
|
406
410
|
"""
|
|
407
411
|
n, ignore_no_item_found, strict_n = defaulted_values(
|
|
@@ -421,6 +425,7 @@ class BufferReader:
|
|
|
421
425
|
# strict_n = strict_n or self._read_kwargs['strict_n']
|
|
422
426
|
|
|
423
427
|
if blocking is True:
|
|
428
|
+
deadline = None if timeout is None else time.monotonic() + timeout
|
|
424
429
|
while True:
|
|
425
430
|
_read = self.read(
|
|
426
431
|
n,
|
|
@@ -433,8 +438,13 @@ class BufferReader:
|
|
|
433
438
|
return _read
|
|
434
439
|
elif self.is_stopped:
|
|
435
440
|
return None
|
|
436
|
-
|
|
441
|
+
elif deadline is None:
|
|
437
442
|
time.sleep(self._sleep_time_on_iter_none_s)
|
|
443
|
+
else:
|
|
444
|
+
remaining = deadline - time.monotonic()
|
|
445
|
+
if remaining <= 0:
|
|
446
|
+
return None
|
|
447
|
+
time.sleep(min(self._sleep_time_on_iter_none_s, remaining))
|
|
438
448
|
|
|
439
449
|
with self._buffer.reader_lock() as reader:
|
|
440
450
|
try:
|
|
@@ -74,3 +74,17 @@ def test_buffer_reader_blocking_stops_on_stop_event():
|
|
|
74
74
|
# Should have gotten None because buffer stopped
|
|
75
75
|
assert len(results) == 1
|
|
76
76
|
assert results[0] is None, "Blocking read should return None when stopped"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_buffer_reader_blocking_timeout():
|
|
80
|
+
"""A blocking read gives up after ``timeout`` seconds, and only then."""
|
|
81
|
+
with StreamBuffer(SimpleSourceReader(range(3)), maxlen=100) as buffer:
|
|
82
|
+
reader = buffer.mk_reader()
|
|
83
|
+
assert wait_until(lambda: len(buffer.source_buffer) >= 3)
|
|
84
|
+
# data available: timeout is irrelevant
|
|
85
|
+
assert reader.read(n=3, blocking=True, timeout=5) is not None
|
|
86
|
+
# no more data: returns None once the timeout has elapsed
|
|
87
|
+
start = time.monotonic()
|
|
88
|
+
assert reader.read(blocking=True, timeout=0.3) is None
|
|
89
|
+
elapsed = time.monotonic() - start
|
|
90
|
+
assert 0.3 <= elapsed < 2
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_buffer_reader.rst
RENAMED
|
File without changes
|
{stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_lock_sorted_deque.rst
RENAMED
|
File without changes
|
{stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_source_reader.rst
RENAMED
|
File without changes
|
{stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_stream_buffer.rst
RENAMED
|
File without changes
|
{stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/test_stream_source.rst
RENAMED
|
File without changes
|
|
File without changes
|
{stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/tests/utils_for_testing.rst
RENAMED
|
File without changes
|
|
File without changes
|
{stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/utility/locked_sorted_deque.rst
RENAMED
|
File without changes
|
{stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/utility/reader_writer_lock.rst
RENAMED
|
File without changes
|
{stream2py-1.0.46 → stream2py-1.0.47}/docsrc/module_docs/stream2py/utility/sorted_collection.rst
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|