fixed block on stdin empty
This commit is contained in:
@@ -41,7 +41,7 @@ if __name__ == "__main__":
|
|||||||
except IOError as e:
|
except IOError as e:
|
||||||
print(f"Cannot read '{input_file}': {e}", file=sys.stderr)
|
print(f"Cannot read '{input_file}': {e}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif not sys.stdin.isatty():
|
elif utils.is_stdin_ready():
|
||||||
input_data = utils.read_stream(sys.stdin.buffer)
|
input_data = utils.read_stream(sys.stdin.buffer)
|
||||||
|
|
||||||
img, errors = meme_otron.compute(*sys.argv[1:], input_data=input_data, wmark=wmark, debug=debug)
|
img, errors = meme_otron.compute(*sys.argv[1:], input_data=input_data, wmark=wmark, debug=debug)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import re
|
import re
|
||||||
|
import select
|
||||||
import sys
|
import sys
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
from urllib.error import URLError
|
from urllib.error import URLError
|
||||||
@@ -220,6 +221,13 @@ def safe_index(src: Union[str, list], pattern, start: int = 0):
|
|||||||
# region bytes utils
|
# 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:
|
def read_stream(stream: BinaryIO) -> bytes:
|
||||||
output_data = bytearray()
|
output_data = bytearray()
|
||||||
for line in stream:
|
for line in stream:
|
||||||
|
|||||||
Reference in New Issue
Block a user