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

Skip to content

Allow streamlink to exit faster when using Ctrl-C#1658

Merged
gravyboat merged 1 commit into
streamlink:masterfrom
beardypig:thread-blocking-exit
May 29, 2018
Merged

Allow streamlink to exit faster when using Ctrl-C#1658
gravyboat merged 1 commit into
streamlink:masterfrom
beardypig:thread-blocking-exit

Conversation

@beardypig

Copy link
Copy Markdown
Member

The segmented stream downloader uses a threadpool to allow multiple segments to be downloaded simultaneously. The thread pool installs an atexit hook so that causes them to complete their current tasks, this means that if segments are still downloading streamlink will continue running until the segments are downloading.

By unregistering this atexit hook (because there aren't any consistency issues) the exit time can be sped up in some cases.

See #521.

@beardypig

beardypig commented May 16, 2018

Copy link
Copy Markdown
Member Author

Only works for Python 3+, hence the build errors.

Updated with alternative version that clears concurrent.futures.thread._threads_queues, which the exit hook loops through to join all the threads.

The segmented stream downloader uses a threadpool to allow multiple
segments to be downloaded simultaneously. The thread pool installs an
atexit hook so that causes them to complete their current tasks, this
means that if segments are still downloading streamlink will continue
running until the segments are downloading.

The exit hook loops `concurrent.futures.thread._threads_queues` and
joins all the threads in that queue. By clearing the queue we can avoid
joining and exit earlier - the threads being killed shouldn't cause any
consistency issues as they are just downloading and not writing/updating
anything (or, they shouldn't be).
@beardypig beardypig force-pushed the thread-blocking-exit branch from 06c670e to d285e3a Compare May 16, 2018 15:26
@codecov

codecov Bot commented May 16, 2018

Copy link
Copy Markdown

Codecov Report

Merging #1658 into master will increase coverage by 0.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1658      +/-   ##
==========================================
+ Coverage   33.17%   33.18%   +0.01%     
==========================================
  Files         229      229              
  Lines       12898    12912      +14     
==========================================
+ Hits         4279     4285       +6     
- Misses       8619     8627       +8

@beardypig

Copy link
Copy Markdown
Member Author

@gravyboat if you get time to look at this one as well.

@gravyboat

Copy link
Copy Markdown
Member

Looks good to me, nice fix @beardypig.

@gravyboat gravyboat merged commit 08e23ee into streamlink:master May 29, 2018
mkbloke pushed a commit to mkbloke/streamlink that referenced this pull request Aug 18, 2020
Allow streamlink to exit faster when using Ctrl-C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants