From f84557cc809745af73fbcd2e5782dea36c4e4b4d Mon Sep 17 00:00:00 2001 From: sezanzeb Date: Sun, 22 Nov 2020 21:02:44 +0100 Subject: [PATCH] improved error handling --- keymapper/injector.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/keymapper/injector.py b/keymapper/injector.py index 4b088b45..f6befc39 100644 --- a/keymapper/injector.py +++ b/keymapper/injector.py @@ -64,7 +64,7 @@ def _grab(path): logger.debug('Failed attemt to grab %s %d', path, attempts) if attempts >= 4: - logger.error('Cannot grab %s', path) + logger.error('Cannot grab %s, it is possibly in use', path) return None # it might take a little time until the device is free if @@ -124,7 +124,12 @@ def _start_injecting_worker(path, pipe, mapping): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - device = _grab(path) + try: + device = _grab(path) + except Exception as e: + logger.error(e) + pipe.send(FAILED) + return if device is None: pipe.send(FAILED) @@ -151,10 +156,6 @@ def _start_injecting_worker(path, pipe, mapping): for event in device.read_loop(): if event.type != evdev.ecodes.EV_KEY: - logger.spam( - 'got type:%s code:%s value:%s, forward', - event.type, event.code, event.value - ) keymapper_device.write(event.type, event.code, event.value) # this already includes SYN events, so need to syn here again continue @@ -259,7 +260,7 @@ class KeycodeInjector: # wait for the process to notify creation of the new injection # device, to keep the logs in order. status = pipe[0].recv() - if status != FAILED: + if status == DEVICE_CREATED: self.processes.append(worker) else: worker.join()