From 58d06c4e513e035f15710e7f176fa8e39bcda5e6 Mon Sep 17 00:00:00 2001 From: Matthew Blecker Date: Tue, 16 Oct 2018 12:51:11 -0700 Subject: ec3po console and interpreter: Handle EOFError from the pipes. EOF is expected sometimes upon shutdown, when one thread (console or interpreter) manages to close its write side of a pipe before the other thread receives the shutdown pipe unblocked notification. EOF is now considered another indication to shutdown. BRANCH=none BUG=b:79684405 TEST=With this change plus CL:1279145 to switch to threading, I am no longer able to reproduce the formerly occasional EOFError tracebacks upon shutdown, with either ctrl+c or SIGTERM. Basic servod functionality continues to work, including dut-control ec_uart_pty, servo_console_pty (both tested with minicom), dut_i2c_mux, enable_ite_dfu, get_ite_chipid. Testing performed with a servo_micro connected to an octopus_ite. I tested both without and with CL:1279145 i.e. both with subprocesses and with threads (though I only ever encountered EOFError with the latter). Change-Id: Iaa1ddc5f05a32ef806fa5f84d0ed0ad4739189ce Signed-off-by: Matthew Blecker Reviewed-on: https://chromium-review.googlesource.com/1284509 Reviewed-by: Nick Sanders Reviewed-by: Ruben Rodriguez Buchillon --- util/ec3po/interpreter.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'util/ec3po/interpreter.py') diff --git a/util/ec3po/interpreter.py b/util/ec3po/interpreter.py index fd811716de..86272f6646 100644 --- a/util/ec3po/interpreter.py +++ b/util/ec3po/interpreter.py @@ -347,7 +347,11 @@ class Interpreter(object): self.dbg_pipe.send(data) def HandleUserData(self): - """Handle any incoming commands from the user.""" + """Handle any incoming commands from the user. + + Raises: + EOFError: Allowed to propagate through from self.cmd_pipe.recv(). + """ self.logger.log(1, 'Command data available. Begin processing.') data = self.cmd_pipe.recv() # Process the command. @@ -418,11 +422,17 @@ def StartLoop(interp, shutdown_pipe=None): # Handle any commands from the user. elif obj is interp.cmd_pipe: - interp.HandleUserData() + try: + interp.HandleUserData() + except EOFError: + interp.logger.debug( + 'ec3po interpreter received EOF from cmd_pipe in ' + 'HandleUserData()') + continue_looping = False elif obj is shutdown_pipe: interp.logger.debug( - 'ec3po console received shutdown pipe unblocked notification') + 'ec3po interpreter received shutdown pipe unblocked notification') continue_looping = False for obj in writeable: -- cgit v1.2.1