Skip to content

Instantly share code, notes, and snippets.

@ttback
Last active December 28, 2015 08:09
Show Gist options
  • Save ttback/7469849 to your computer and use it in GitHub Desktop.
Save ttback/7469849 to your computer and use it in GitHub Desktop.
Python custom error handler with lock
class ErrorHandler (logging.Handler):
def __init__(self):
logging.Handler.__init__(self)
self.lock = multiprocessing.Lock()
self.errorLogMessages = list()
def emit (self, record):
print record
self.lock.acquire()
print "lock acquired"
try:
print "==================================="
self.errorLogMessages.append(self.format(record))
print ",".join(self.errorLogMessages)
finally:
self.lock.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment