Having multiple YoutubeDL objects open simultaneously
See original GitHub issueDO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
- I understand that I will be blocked if I remove or skip any mandatory* field
Checklist
- I’m asking a question and not reporting a bug or requesting a feature
- I’ve looked through the README
- I’ve verified that I’m running yt-dlp version 2022.09.01 (update instructions) or later (specify commit)
- I’ve searched the bugtracker for similar questions including closed ones. DO NOT post duplicates
- I’ve read the guidelines for opening an issue
Please make sure the question is worded well enough to be understood
Instances of the YoutubeDL
class are supposed to be used with a context manager:
with YoutubeDL(opts) as ydl:
... # do stuff with ydl
I have looked at (though not fully understood) the __enter__()
and __exit__()
code. __exit__()
saves cookies to a file if one is explicitly specified, which I don’t. Is there anything else I need to worry about or is it okay for me to do the following?
with YoutubeDL(opts1) as ydl1, YoutubeDL(opts2) as ydl2:
...
To make clear why this is concerning me: The code might make the assumption that only one YoutubeDL
object is open at a time, like the cookie file code probably does, and produce erroneous behavior if that is not the case and the multiple instances “interfere with each other.”
I want to do things this way because constructing a YoutubeDL
instance is runtime-intensive, so I would like to to avoid doing that each time I switch between options.
I am using {"cachedir": False}
as part of both opts
in case that matters.
Provide verbose output that clearly demonstrates the problem
- Run your yt-dlp command with -vU flag added (
yt-dlp -vU <your command line>
) - Copy the WHOLE output (starting with
[debug] Command-line config
) and insert it below
Complete Verbose Output
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
As far as I know, it should be fine. But this use-case is not well tested, so I can’t be 100% sure. If you find any issues, let me know and we can fix it
No. Cache files are open and closed as required. Since your code isn’t multithreaded, it is fine