Permalink
Browse files

Be careful with logging locks and unopened streams

Slight modification of patch suggested by sirkonst.
  • Loading branch information...
1 parent ac223ae commit 1757567d2f5c37d1092524167242b918bfdcc402 @tilgovi tilgovi committed Mar 28, 2012
Showing with 12 additions and 6 deletions.
  1. +12 −6 gunicorn/glogging.py
View
@@ -206,18 +206,24 @@ def reopen_files(self):
for handler in log.handlers:
if isinstance(handler, logging.FileHandler):
handler.acquire()
- handler.stream.close()
- handler.stream = open(handler.baseFilename,
- handler.mode)
- handler.release()
+ try:
+ if handler.stream:
+ handler.stream.close()
+ handler.stream = open(handler.baseFilename,
+ handler.mode)
+ finally:
+ handler.release()
def close_on_exec(self):
for log in (self.error_log, self.access_log):
for handler in log.handlers:
if isinstance(handler, logging.FileHandler):
handler.acquire()
- util.close_on_exec(handler.stream.fileno())
- handler.release()
+ try:
+ if handler.stream:
+ util.close_on_exec(handler.stream.fileno())
+ finally:
+ handler.release()
def _get_gunicorn_handler(self, log):

0 comments on commit 1757567

Please sign in to comment.