diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 2a0fabfd73..08d608a52d 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -962,8 +962,9 @@ class YoutubeDL: def close(self): self.save_cookies() - self._request_director.close() - del self._request_director + if '_request_director' in self.__dict__: + self._request_director.close() + del self._request_director def trouble(self, message=None, tb=None, is_error=True): """Determine action to take when a download problem appears. diff --git a/yt_dlp/networking/common.py b/yt_dlp/networking/common.py index 7da2652ae5..e43d74eadc 100644 --- a/yt_dlp/networking/common.py +++ b/yt_dlp/networking/common.py @@ -68,7 +68,7 @@ class RequestDirector: def close(self): for handler in self.handlers.values(): handler.close() - self.handlers = {} + self.handlers.clear() def add_handler(self, handler: RequestHandler): """Add a handler. If a handler of the same RH_KEY exists, it will overwrite it"""