mirror of
https://github.com/blackjack4494/yt-dlc.git
synced 2024-12-21 23:33:10 +00:00
[heartbeat] replace daemon=True with join, send exception traceback to stderr
This commit is contained in:
parent
729b407626
commit
89ada4406a
1 changed files with 9 additions and 7 deletions
|
@ -1,12 +1,12 @@
|
|||
# coding: utf-8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import time
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
from .utils import (
|
||||
compat_str,
|
||||
encode_compat_str,
|
||||
sanitized_Request
|
||||
)
|
||||
|
||||
|
@ -27,11 +27,11 @@ class Heartbeat(object):
|
|||
|
||||
self.interval = params.get('interval', 30)
|
||||
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):
|
||||
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()
|
||||
|
||||
def cancel(self):
|
||||
|
@ -49,7 +49,9 @@ class Heartbeat(object):
|
|||
self.ydl.to_screen('[heartbeat]')
|
||||
self.ydl.urlopen(self.request)
|
||||
except Exception:
|
||||
self.ydl.report_warning("[heartbeat] Heartbeat failed")
|
||||
if self.ydl.params.get('verbose'):
|
||||
traceback.print_exc()
|
||||
self.ydl.to_screen("[heartbeat] Heartbeat failed")
|
||||
time.sleep(self.interval)
|
||||
self.ydl.to_stderr(encode_compat_str(traceback.format_exc()))
|
||||
self.parent_thread.join(self.interval)
|
||||
if not self.parent_thread.is_alive():
|
||||
break
|
||||
|
|
Loading…
Reference in a new issue