stream.segmented: gracefully shut down thread pool
stream.segmented: gracefully shut down thread pool

Backports `ThreadPoolExecutor.shutdown` from Python 3.9, which adds the
`cancel_futures` parameter and clears the thread queue of the current
executor instance instead of the global thread queue.

Also let the writer thread wait for the thread pool executor to fully
shut down on close, so that it can be joined safely by the main thread.

beardypig/streamlink,chhe/streamlink,gravyboat/streamlink,streamlink/streamlink,beardypig/streamlink,chhe/streamlink,bastimeyer/streamlink,melmorabity/streamlink,melmorabity/streamlink,gravyboat/streamlink,bastimeyer/streamlink,streamlink/streamlink