Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
[QUESTION] How to interrupt a running youtube-dl thread, using embedded python #16175
Comments
|
I am also interested in this question. Would love to see an "official" way to handle interruption. |
|
I was hoping it might be possible somehow to terminate the download from a progress hook, since every |
|
I guess one potentially messy solution would be to sart youtube-dl in a separate process using multiprocessing and then kill that process as needed when some condition occurs? |
|
Just raise a valueError inside progress callback function (works if callback is actively called and no subprocess involved i.e no live streams :/) |
Could you please explain what you mean? Hm even if I run it via multiprocessing, ytdl spawns ffmpeg to download the stream and this continues running in a separate process without python. |
well true, it just does in a separate process in ffmpeg to download live stream and as explained here why "q" doesn't work and we have to use ctrl+c and seems like theres no other native way to stop it and even callback hooks gets called at the end so the only way to do is send a SIGINT signal to the process. (ugly way) |
Please follow the guide below
xinto all the boxes [ ] relevant to your issue (like this:[x])Make sure you are using the latest version: run
youtube-dl --versionand ensure your version is 2018.04.09. If it's not, read this FAQ entry and update. Issues with outdated version will be rejected.Before submitting an issue make sure you have:
What is the purpose of your issue?
Description of your issue, suggested solution and other information
I'm using the youtube_dl Python module as explained here. It works fine stand-alone, however I now want to connect a simple graphical progress indicator to it, so I'm running the widget and youtube_dl in separate threads. The widget will have a progress indicator and a "stop" button. The progress indicator is updated when my progress_hook is called. However, I'm looking for a way to tell the youtube_dl thread to terminate (gracefully or not, whatever) when the user clicks the "stop" button. The command-line version of youtube_dl just catches KeyboardInterrupt and terminates, but I've found no documentation on how to do this cleanly (if there's a way at all) when using the embedded module.
Since the progress_hook seems to be the only place where user code can do something, I was thinking of setting a "stop" flag from the main thread and checking it in the youtube_dl thread when the progress_hook is called, and if it's set then calling sys.exit() in the youtube_dl thread to terminate. Is there a better way?
Thanks.