Last active
December 28, 2015 08:09
-
-
Save ttback/7469849 to your computer and use it in GitHub Desktop.
Python custom error handler with lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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