1
0
Fork 0
mirror of https://github.com/blackjack4494/yt-dlc.git synced 2024-12-22 07:43:08 +00:00

[heartbeat] replace daemon=True with join, send exception traceback to stderr

This commit is contained in:
insaneracist 2020-11-03 14:00:30 -08:00
parent 729b407626
commit 89ada4406a

View file

@ -1,12 +1,12 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import time
import threading import threading
import traceback import traceback
from .utils import ( from .utils import (
compat_str, compat_str,
encode_compat_str,
sanitized_Request sanitized_Request
) )
@ -27,11 +27,11 @@ class Heartbeat(object):
self.interval = params.get('interval', 30) self.interval = params.get('interval', 30)
self.cancelled = False self.cancelled = False
self.thread = threading.Thread(target=self.__heartbeat, daemon=True) self.parent_thread = threading.current_thread()
self.thread = threading.Thread(target=self.__heartbeat)
def start(self): def start(self):
if self.ydl.params.get('verbose'): self.ydl.to_screen('[heartbeat] Heartbeat every %s seconds' % self.interval)
self.ydl.to_screen('[heartbeat] Heartbeat every %s seconds' % self.interval)
self.thread.start() self.thread.start()
def cancel(self): def cancel(self):
@ -49,7 +49,9 @@ class Heartbeat(object):
self.ydl.to_screen('[heartbeat]') self.ydl.to_screen('[heartbeat]')
self.ydl.urlopen(self.request) self.ydl.urlopen(self.request)
except Exception: except Exception:
self.ydl.report_warning("[heartbeat] Heartbeat failed")
if self.ydl.params.get('verbose'): if self.ydl.params.get('verbose'):
traceback.print_exc() self.ydl.to_stderr(encode_compat_str(traceback.format_exc()))
self.ydl.to_screen("[heartbeat] Heartbeat failed") self.parent_thread.join(self.interval)
time.sleep(self.interval) if not self.parent_thread.is_alive():
break