Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions exiftool/exiftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"""

# ---------- standard Python imports ----------
import select
import selectors
import subprocess
import os
import shutil
Expand Down Expand Up @@ -114,6 +114,10 @@ def _read_fd_endswith(fd, b_endswith: bytes, block_size: int) -> bytes:

if you're not careful, on windows, this will block
"""
if not constants.PLATFORM_WINDOWS:
selector = selectors.DefaultSelector()
selector.register(fd, selectors.EVENT_READ)

output_list: List[bytes] = []

# if we're only looking at the last few bytes, make it meaningful. 4 is max size of \r\n? (or 2)
Expand All @@ -129,9 +133,9 @@ def _read_fd_endswith(fd, b_endswith: bytes, block_size: int) -> bytes:
output_list.append(os.read(fd, block_size))
else: # pytest-cov:windows: no cover
# this does NOT work on windows... and it may not work on other systems... in that case, put more things to use the original code above
inputready, outputready, exceptready = select.select([fd], [], [])
for i in inputready:
if i == fd:
events = selector.select()
for key, _ in events:
if key.fd == fd:
output_list.append(os.read(fd, block_size))

return b"".join(output_list)
Expand Down