Skip to contentSkip to conversation

cooker.py: Close lock file and watcher fds when end.

PATCH In review Aníbal Limón 2 participants 3 messages Jul 3, 2015 – Jul 7, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 cooker.py: Close lock file and watcher fds when end.

When run cooker inside loop it reaches OS max fd's causing an exception.

---
 lib/bb/cooker.py | 3 +++
 1 file changed, 3 insertions(+)
lib/bb/cooker.py +3 -0
index f31bca6..abe8a52 100644
@@ -1432,6 +1432,9 @@ class BBCooker:
         if self.state in (state.shutdown, state.forceshutdown, state.error):
             if hasattr(self.parser, 'shutdown'):
                 self.parser.shutdown(clean=False, force = True)
+            self.configwatcher.close()
+            self.watcher.close()
+            self.lock.close()
             raise bb.BBHandledException()
 
         if self.state != state.parsing:
Signature · 1 line
1.9.1
#1 lore raw

PATCH 2/2 tinfoil.py: Add shutdown method.

When run tinfoil in a loop it causing problems for don't free resources like OS max fd exception.

---
 lib/bb/tinfoil.py | 8 ++++++++
 1 file changed, 8 insertions(+)
lib/bb/tinfoil.py +8 -0
index 8fc9be3..5025e62 100644
@@ -28,6 +28,7 @@ import bb.utils
 from bb.cooker import state, BBCooker, CookerFeatures
 from bb.cookerdata import CookerConfiguration, ConfigParameters
 import bb.fetch2
+from bb import BBHandledException
 
 class Tinfoil:
     def __init__(self, output=sys.stdout, tracking=False):
@@ -84,6 +85,13 @@ class Tinfoil:
             else:
                 self.parseRecipes()
 
+    def shutdown(self):
+        try:
+            self.cooker.shutdown()
+            self.cooker.updateCache()
+        except BBHandledException:
+            pass
+
 class TinfoilConfigParameters(ConfigParameters):
 
     def __init__(self, **options):
Signature · 1 line
1.9.1
#2 lore raw
In reply to Aníbal Limón
Quoted 13 lines · Aníbal Limón

When run cooker inside loop it reaches OS max fd's causing an exception.

---
 lib/bb/cooker.py | 3 +++
 1 file changed, 3 insertions(+)
lib/bb/cooker.py +0 -0
index f31bca6..abe8a52 100644

lib/bb/cooker.py class BBCooker: · line 1440

Quoted 9 lines
lib/bb/cooker.py +3 -0
@@ -1432,6 +1432,9 @@ class BBCooker:
         if self.state in (state.shutdown, state.forceshutdown, state.error):
             if hasattr(self.parser, 'shutdown'):
                 self.parser.shutdown(clean=False, force = True)
+            self.configwatcher.close()
+            self.watcher.close()
+            self.lock.close()
             raise bb.BBHandledException()
 
         if self.state != state.parsing:

Burying this cleanup into the updateCache function seems wrong. The updateCache call as you use it in tinfoil highlights how odd that is.

We really need a better shutdown mechanism of cooker. It'll be more invasive to the codebase but better in the long run I think...

Cheers,

Richard