diff --git a/slapos/recipe/librecipe/execute.py b/slapos/recipe/librecipe/execute.py
index 1b229bb9285f3de095662e4f47bc41fd10efc56a..bd767409913f8eae49d1a0bc2cd4e5f46d262a63 100644
--- a/slapos/recipe/librecipe/execute.py
+++ b/slapos/recipe/librecipe/execute.py
@@ -43,7 +43,8 @@ def _wait_files_creation(file_list):
             directories[dirname][event.name] = True
 
   finally:
-    os.close(fd)
+    if isinstance(fd, int):
+      os.close(fd)
 
 def execute(args):
   """Portable execution with process replacement"""
diff --git a/slapos/recipe/librecipe/inotify.py b/slapos/recipe/librecipe/inotify.py
index 3448ab7d39704e448cd0ad9ac4f42efed2b71865..b93a876dc13bbd2b60eff46630888f7d0e45a4ae 100644
--- a/slapos/recipe/librecipe/inotify.py
+++ b/slapos/recipe/librecipe/inotify.py
@@ -48,4 +48,5 @@ def subfiles(directory):
       subfiles = [file_.name for file_ in inotifyx.get_events(watchfd)]
 
   finally:
-    os.close(watchfd)
+    if isinstance(watchfd, int): 
+      os.close(watchfd)
diff --git a/slapos/recipe/lockfile.py b/slapos/recipe/lockfile.py
index b27975f50457d880e1e542672635fdb313d5f5f9..897b0ca412048577c75ae33a7253d4fec39e8289 100644
--- a/slapos/recipe/lockfile.py
+++ b/slapos/recipe/lockfile.py
@@ -57,7 +57,8 @@ class LockFile(object):
     except IOError: # add_watch failed
       pass
     finally:
-      os.close(inotify_fd)
+        if isinstance(inotify_fd, int):
+          os.close(inotify_fd)
 
     self.__enter__()