1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Extend custom exception_handler behaviour

This commit is contained in:
Badiboy
2022-02-01 23:58:57 +03:00
parent 9fa79aabc0
commit ce56a035b5
2 changed files with 19 additions and 5 deletions

View File

@@ -114,7 +114,8 @@ class WorkerThread(threading.Thread):
class ThreadPool:
def __init__(self, num_threads=2):
def __init__(self, telebot, num_threads=2):
self.telebot = telebot
self.tasks = Queue.Queue()
self.workers = [WorkerThread(self.on_exception, self.tasks) for _ in range(num_threads)]
self.num_threads = num_threads
@@ -126,8 +127,13 @@ class ThreadPool:
self.tasks.put((func, args, kwargs))
def on_exception(self, worker_thread, exc_info):
self.exception_info = exc_info
self.exception_event.set()
if self.telebot.exception_handler is not None:
handled = self.telebot.exception_handler.handle(exc_info)
else:
handled = False
if not handled:
self.exception_info = exc_info
self.exception_event.set()
worker_thread.continue_event.set()
def raise_exceptions(self):