summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-04-08 21:32:45 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-04-08 21:35:43 +0900
commit60ad1c41f94b0f1df716f613a179ed32540c051e (patch)
treee013b5a7475f296daf6ebe8e9a1aa2de00535d42
parent6b2f1de5763f13fd92d285b63399d39d993221e1 (diff)
downloadbuildstream-60ad1c41f94b0f1df716f613a179ed32540c051e.tar.gz
element.py: Handle log flushing at termination more carefully
If the child process is in the middle of using the I/O stack in python while trying to flush the python file handle, this is non reentrant and will raise an exception. Handle this exception and simply flush the underlying file descriptor instead.
-rw-r--r--buildstream/element.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index 332cb0fc5..46422b44c 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -749,9 +749,17 @@ class Element(Plugin):
# Write one last line to the log and flush it to disk
def flush_log():
- logfile.write('\n\nAction {} for element {} forcefully terminated\n'
- .format(action_name, self.name))
- logfile.flush()
+
+ # If the process currently had something happening in the I/O stack
+ # then trying to reenter the I/O stack will fire a runtime error.
+ #
+ # So just try to flush as well as we can at SIGTERM time
+ try:
+ logfile.write('\n\nAction {} for element {} forcefully terminated\n'
+ .format(action_name, self.name))
+ logfile.flush()
+ except RuntimeError:
+ os.fsync(logfile.fileno())
self._set_log_handle(logfile)
with _signals.terminator(flush_log):