fixed block on stdin empty

This commit is contained in:
klemek
2020-04-29 13:00:14 +02:00
parent f44e32fbf8
commit 7c0e292c91
2 changed files with 9 additions and 1 deletions
+8
View File
@@ -1,4 +1,5 @@
import re
import select
import sys
from urllib.request import urlopen
from urllib.error import URLError
@@ -220,6 +221,13 @@ def safe_index(src: Union[str, list], pattern, start: int = 0):
# region bytes utils
def is_stdin_ready() -> bool:
"""
https://stackoverflow.com/questions/3762881/how-do-i-check-if-stdin-has-some-data
"""
return sys.stdin.isatty() and select.select([sys.stdin, ], [], [], 0.0)[0]
def read_stream(stream: BinaryIO) -> bytes:
output_data = bytearray()
for line in stream: