From 61ff3086313b5e6c321adb14969938b429549260 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Tue, 23 Apr 2024 18:23:27 +0200 Subject: Removing pipe properly at the end. --- src/argaze/__main__.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/argaze/__main__.py b/src/argaze/__main__.py index 091b660..b94e5ec 100644 --- a/src/argaze/__main__.py +++ b/src/argaze/__main__.py @@ -22,6 +22,7 @@ import logging import json import contextlib import os +import stat from . import load from .ArFeatures import ArCamera, ArContext, PostProcessingContext, LiveProcessingContext @@ -45,9 +46,10 @@ logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG if # Manage pipe communication if args.pipe_path is not None: + # Create FIFO if not os.path.exists(args.pipe_path): - os.mkfifo(args.pipe_path) + os.mkfifo(args.pipe_path) # Open the fifo in non-blocking mode or it will stalls until someone opens it for writting pipe_file = os.open(args.pipe_path, os.O_RDONLY | os.O_NONBLOCK) @@ -91,19 +93,19 @@ with load(args.context_file) as context: # Read message from pipe if required if args.pipe_path is not None: - message = pipe.read().rstrip('\n') + try: - if message: + message = pipe.read().rstrip('\n') - logging.info('%s: %s', args.pipe_path, message) + if message: - try: + logging.info('%s pipe received: %s', args.pipe_path, message) exec(message) - except Exception as e: + except Exception as e: - logging.error('%s', e) + logging.error('%s', e) # Window mode on if not args.no_window: @@ -153,3 +155,13 @@ with load(args.context_file) as context: # Stop frame display cv2.destroyAllWindows() + + # Manage pipe communication + if args.pipe_path is not None: + + # Remove pipe + if os.path.exists(args.pipe_path): + + os.remove(args.pipe_path) + + logging.info('%s pipe closed', args.pipe_path) -- cgit v1.1