Explorar o código

Catch race condition; if the file is already deleted, don't crash.

Chris McDonough %!s(int64=17) %!d(string=hai) anos
pai
achega
f70ec89331
Modificáronse 1 ficheiros con 12 adicións e 2 borrados
  1. 12 2
      src/supervisor/loggers.py

+ 12 - 2
src/supervisor/loggers.py

@@ -210,11 +210,21 @@ class RotatingFileHandler(FileHandler):
                 dfn = "%s.%d" % (self.baseFilename, i + 1)
                 if os.path.exists(sfn):
                     if os.path.exists(dfn):
-                        os.remove(dfn)
+                        try:
+                            os.remove(dfn)
+                        except OSError, why:
+                            # catch race condition (already deleted)
+                            if why[0] != errno.ENOENT:
+                                raise
                     os.rename(sfn, dfn)
             dfn = self.baseFilename + ".1"
             if os.path.exists(dfn):
-                os.remove(dfn)
+                try:
+                    os.remove(dfn)
+                except OSError, why:
+                    # catch race condition (already deleted)
+                    if why[0] != errno.ENOENT:
+                        raise
             os.rename(self.baseFilename, dfn)
         self.stream = open(self.baseFilename, 'w')