Skip to content

Commit

Permalink
Added wrapper to method threads so we can log the exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Apr 7, 2014
1 parent c35de9c commit dd5212d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Trakttv.bundle/Contents/Code/core/method_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from core.logger import Logger
from core.plugin import ACTIVITY_MODE
import threading
import traceback

log = Logger('core.method_manager')

Expand All @@ -11,7 +12,7 @@ class Method(object):

def __init__(self, threaded=True):
if threaded:
self.thread = threading.Thread(target=self.run, name=self.get_name())
self.thread = threading.Thread(target=self.run_wrapper, name=self.get_name())
self.running = False

self.threaded = threaded
Expand All @@ -30,6 +31,13 @@ def start(self):
self.thread.start()
self.running = True

def run_wrapper(self):
# Wrap run method to catch any exceptions
try:
self.run()
except Exception, ex:
log.error(traceback.format_exc())

def run(self):
raise NotImplementedError()

Expand Down

0 comments on commit dd5212d

Please sign in to comment.