Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cli: threaded read_stream()#4974

Closed
bastimeyer wants to merge 1 commit into
streamlink:masterfrom
bastimeyer:cli/threaded-read-stream
Closed

cli: threaded read_stream()#4974
bastimeyer wants to merge 1 commit into
streamlink:masterfrom
bastimeyer:cli/threaded-read-stream

Conversation

@bastimeyer

@bastimeyer bastimeyer commented Nov 16, 2022

Copy link
Copy Markdown
Member

Rewrite streamlink_cli.main.read_stream(), refactor progress thread data feeding, and move player polling into a separate thread which closes the reader once the player process terminates or gets killed.

This fixes the player polling issue, or rather the detection of its broken pipe while reading the stream, as stream read calls can stall for various reasons, e.g. due to segmented streams or the filtering of stream data which pauses the stream output and disables any timeouts.


Resolves #4642

As mentioned in #4642, there are still no tests written for read_stream(). I will be thinking about writing ones for a bit first before I'm going to mark this PR as ready. I also haven't fully tested this in production yet, only with a simple player stdin pipe as output, and only on my Linux system.

@bastimeyer bastimeyer added the CLI label Nov 16, 2022
@bastimeyer bastimeyer force-pushed the cli/threaded-read-stream branch from 1924116 to 3b5f8b9 Compare November 16, 2022 17:25
Rewrite `streamlink_cli.main.read_stream()`, refactor progress thread
data feeding, and move player polling into a separate thread which
closes the reader once the player process terminates or gets killed.

This fixes the player polling issue, or rather the detection of its
broken pipe while reading the stream, as stream read calls can stall
for various reasons, e.g. due to segmented streams or the filtering
of stream data which pauses the stream output and disables any timeouts.
@bastimeyer bastimeyer force-pushed the cli/threaded-read-stream branch from 3b5f8b9 to 1702f1a Compare December 1, 2022 17:19
@bastimeyer

Copy link
Copy Markdown
Member Author

I've updated and rewritten the PR changes. Please check.

The player polling now stops immediately via a threading.Event and subprocess.Popen().poll() instead of subprocess.Popen().wait(), and "Player closed" gets logged once in both cases, when the write() call fails (due to a broken pipe, etc) or when the player process was terminated/killed. I've also fixed the incorrect stream.closed check in the read-loop, which led to stream data not being fully read from the buffer when the stream ended regularly. The polling thread also did not get closed gracefully when the stream ended this way.

Still no tests though. I made some efforts, but it's a lot of boilerplate code dealing with three threads (main test thread, CLI "main" read thread and player polling thread) and testing all the timings between all possible scenarios.

@bastimeyer bastimeyer requested a review from back-to December 1, 2022 17:29
@bastimeyer

Copy link
Copy Markdown
Member Author

Going to close this... I will open a new PR with a complete code refactor of the read_stream() method that moves the logic into a dedicated module with classes that can actually be tested instead of the current mess. Not finished yet though, but I'm 100% sure that I don't want to continue this work here, and I don't want to rebase again.

@bastimeyer bastimeyer closed this Dec 6, 2022
@bastimeyer bastimeyer deleted the cli/threaded-read-stream branch December 6, 2022 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli: threaded read_stream() for undelayed process termination

1 participant