# -*- coding: utf-8 -*-
import os
import sys
import threading
import traceback
import signal
import tempfile
from datetime import datetime
import time
import faulthandler
def test():
while True:
print(datetime.now())
time.sleep(2)
def dump_thread(signum, frame):
try:
file = os.path.join(tempfile.gettempdir(), datetime.now().strftime('%Y%m%d%H%M%S') + ".log")
with open(file, 'w+') as f:
faulthandler.dump_traceback(file=f, all_threads=True)
except BaseException as e:
print(e)
添加 BackgroundScheduler加入以上代码可观察线上线程信息
self.schedule.add_job(self.dump_thread, 'interval', seconds=interval)