Skip to content

Commit 3583598

Browse files
author
Charles Weir
committed
Added traceback to log when exception caught by Scheduler.
1 parent be4ef48 commit 3583598

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

BrickPython/Scheduler.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import datetime
77
import logging
8+
import sys, traceback
89

910
class StopCoroutineException( Exception ):
1011
'''Exception used to stop a coroutine'''
@@ -51,7 +52,10 @@ def doWork(self):
5152
self.coroutines.remove( coroutine )
5253
except Exception as e:
5354
self.lastExceptionCaught = e
54-
logging.info( "Scheduler - caught: %r, continuing." % (e) )
55+
logging.info( "Scheduler - caught: %r" % (e) )
56+
exc_type, exc_value, exc_traceback = sys.exc_info()
57+
trace = "".join(traceback.format_tb(exc_traceback))
58+
logging.debug( "Traceback (latest call first):\n %s" % trace )
5559
self.coroutines.remove( coroutine )
5660

5761
self.updateCoroutine.next()

test/TestScheduler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from BrickPython.BrickPiWrapper import *
1313
import unittest
14+
import logging
1415
from mock import *
1516

1617
class TestScheduler(unittest.TestCase):
@@ -304,5 +305,6 @@ def outerCoroutine(self):
304305

305306

306307
if __name__ == '__main__':
308+
logging.basicConfig(format='%(message)s', level=logging.DEBUG) # Logging is a simple print
307309
unittest.main()
308310

0 commit comments

Comments
 (0)