Add exception handler for writing to closed log
diff --git a/buildstream/.vscode/settings.json b/buildstream/.vscode/settings.json
new file mode 100644
index 0000000..615aafb
--- /dev/null
+++ b/buildstream/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+    "python.pythonPath": "/usr/bin/python3"
+}
\ No newline at end of file
diff --git a/buildstream/element.py b/buildstream/element.py
index 6fb8261..e44721f 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1407,7 +1407,6 @@
     #   - Cache the resulting artifact
     #
     def _assemble(self):
-
         # Assert call ordering
         assert not self._cached()
 
@@ -1465,7 +1464,7 @@
                                       .format(e))
 
                     raise
-
+                
                 collectdir = os.path.join(sandbox_root, collect.lstrip(os.sep))
                 if not os.path.exists(collectdir):
                     raise ElementError(
@@ -1828,6 +1827,9 @@
                     logfile.flush()
                 except RuntimeError:
                     os.fsync(logfile.fileno())
+                except ValueError:
+                    raise ElementError('Action {} for element {} tried to write to a closed log file.'
+                                    .format(action_name, self.name))
 
             self._set_log_handle(logfile)
             with _signals.terminator(flush_log):