Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] How to interrupt a running youtube-dl thread, using embedded python #16175

Open
waldner opened this issue Apr 13, 2018 · 6 comments
Open

Comments

@waldner
Copy link

@waldner waldner commented Apr 13, 2018

Please follow the guide below

  • You will be asked some questions and requested to provide some information, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your issue (like this: [x])
  • Use the Preview tab to see what your issue will actually look like

Make sure you are using the latest version: run youtube-dl --version and ensure your version is 2018.04.09. If it's not, read this FAQ entry and update. Issues with outdated version will be rejected.

  • I've verified and I assure that I'm running youtube-dl 2018.04.09

Before submitting an issue make sure you have:

  • At least skimmed through the README, most notably the FAQ and BUGS sections
  • Searched the bugtracker for similar issues including closed ones
  • Checked that provided video/audio/playlist URLs (if any) are alive and playable in a browser

What is the purpose of your issue?

  • Question

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.

@waldner waldner changed the title How to interrupt a running youtube-dl thread, using embedded python [QUESTION] How to interrupt a running youtube-dl thread, using embedded python Apr 23, 2018
@yasoob
Copy link
Contributor

@yasoob yasoob commented Feb 3, 2019

I am also interested in this question. Would love to see an "official" way to handle interruption.

@edsu
Copy link

@edsu edsu commented May 5, 2019

I was hoping it might be possible somehow to terminate the download from a progress hook, since every Downloader subclass calls Downloader._hook_progress at certain intervals during the download. But it doesn't seem possible, even if you have an instance of the YoutubeDL object in a closure, because as you say, there's no way to signal the downloader to stop?

@edsu
Copy link

@edsu edsu commented May 5, 2019

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?

@Ripeey
Copy link

@Ripeey Ripeey commented Jan 1, 2020

Just raise a valueError inside progress callback function (works if callback is actively called and no subprocess involved i.e no live streams :/)

@ganego
Copy link

@ganego ganego commented Jun 2, 2020

Just raise a valueError inside prog callback func

Could you please explain what you mean?
I now have the same problem and running ytdl via multiprocessing just to be able to terminate it when it's downloading a stream (mp4 will be destroyed on crash) seems kinda clunky for a Python program.

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.

@Ripeey
Copy link

@Ripeey Ripeey commented Jun 13, 2020

Just raise a valueError inside prog callback func

Could you please explain what you mean?
I now have the same problem and running ytdl via multiprocessing just to be able to terminate it when it's downloading a stream (mp4 will be destroyed on crash) seems kinda clunky for a Python program.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.