From patchwork Mon May 16 14:10:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 15913 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A445EC326E for ; Mon, 16 May 2022 14:10:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D243065672; Mon, 16 May 2022 16:10:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1652710257; bh=PnHyInzBKWeLdu4GkQm2Sbu5jWaEQC26GxZMioyOato=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=b4fzGUI8Ya9kKZ8LKCESsQombsWZte2uMlR+ke6hfPr9SWJ51dZHYA+w0GkQU+fZC K5mWkvkEyIK2WcCaxQjmxWnnEFU5unYZr6eINZH6dHBo1a4BXioQ0Zk9Mcn4fOOGsn QhQNddM0McMoUSBHwOKcAOkk7WcrJGJU2D/6gLevWV5zp4Zqyr47Rc8bQrgpo1Xixg 50VT7/LsSz4THAmsPqmYSujHAb8T1bo6U1DAv/g65fBpp1ofR2c2C1yVCLgfqQGSjr 9g/P8mGyRiykeh8RD6HCRDUADDGxwNqVKdfyDTPTebTZjPpXIvTMkO7+0zf/en+NRT qy3JRi540v16Q== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 731496565C for ; Mon, 16 May 2022 16:10:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XvePJBxT"; dkim-atps=neutral Received: from deskari.lan (91-156-85-209.elisa-laajakaista.fi [91.156.85.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DBF2A484; Mon, 16 May 2022 16:10:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1652710251; bh=PnHyInzBKWeLdu4GkQm2Sbu5jWaEQC26GxZMioyOato=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XvePJBxT/5Iv/6IskRsJhB722UnJtPTLndUSzATnWVK3e6cT3oemOdjLRs9WYFtPA AWQpMxUUbH5eiVYdw1u1e89X8fDT0TCTfQCt77lxBBoW/QrBxiD3TET0AgOhvkMvY7 juNr2o95HYk0CwOgzmu16vGbM0usv5iyL1wCeUQQ= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Mon, 16 May 2022 17:10:15 +0300 Message-Id: <20220516141022.96327-8-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220516141022.96327-1-tomi.valkeinen@ideasonboard.com> References: <20220516141022.96327-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/14] py: cam.py: exit on exception X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Catch exceptions in the event_handler, as they would get ignored otherwise. Print the exception and return False so that the main loop exits. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/cam/cam.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/py/cam/cam.py b/src/py/cam/cam.py index 012b191c..c7da97d7 100755 --- a/src/py/cam/cam.py +++ b/src/py/cam/cam.py @@ -11,6 +11,7 @@ import binascii import libcamera as libcam import os import sys +import traceback class CustomAction(argparse.Action): @@ -286,19 +287,23 @@ def capture_start(contexts): # Called from renderer when there is a libcamera event def event_handler(state): - cm = state['cm'] - contexts = state['contexts'] + try: + cm = state['cm'] + contexts = state['contexts'] - os.read(cm.efd, 8) + os.read(cm.efd, 8) - reqs = cm.get_ready_requests() + reqs = cm.get_ready_requests() - for req in reqs: - ctx = next(ctx for ctx in contexts if ctx['idx'] == req.cookie) - request_handler(state, ctx, req) + for req in reqs: + ctx = next(ctx for ctx in contexts if ctx['idx'] == req.cookie) + request_handler(state, ctx, req) - running = any(ctx['reqs-completed'] < ctx['opt-capture'] for ctx in contexts) - return running + running = any(ctx['reqs-completed'] < ctx['opt-capture'] for ctx in contexts) + return running + except Exception as e: + traceback.print_exc() + return False def request_handler(state, ctx, req):