diff --git a/keymapper/injection/injector.py b/keymapper/injection/injector.py index 81ff15ab..7a886fe2 100644 --- a/keymapper/injection/injector.py +++ b/keymapper/injection/injector.py @@ -35,6 +35,7 @@ from keymapper.mapping import DISABLE_CODE from keymapper.injection.context import Context from keymapper.injection.numlock import set_numlock, is_numlock_on, ensure_numlock from keymapper.injection.consumer_control import ConsumerControl +from keymapper.injection.macros.macro import macro_variables DEV_NAME = "key-mapper" @@ -108,6 +109,8 @@ class Injector(multiprocessing.Process): self._consumer_controls = [] + macro_variables.start() + super().__init__() """Functions to interact with the running process""" diff --git a/keymapper/ipc/shared_dict.py b/keymapper/ipc/shared_dict.py index 754119c3..8ee56e8c 100644 --- a/keymapper/ipc/shared_dict.py +++ b/keymapper/ipc/shared_dict.py @@ -45,9 +45,8 @@ class SharedDict: self.pipe = multiprocessing.Pipe() self.process = None atexit.register(self._stop) - self._start() - def _start(self): + def start(self): """Ensure the process to manage the dictionary is running.""" if self.process is not None and self.process.is_alive(): logger.spam("SharedDict process already running") diff --git a/tests/test.py b/tests/test.py index 6f875220..aa64c703 100644 --- a/tests/test.py +++ b/tests/test.py @@ -573,15 +573,17 @@ def quick_cleanup(log=True): # create a fresh event loop asyncio.set_event_loop(asyncio.new_event_loop()) - if not macro_variables.process.is_alive(): - # nothing should stop the process during runtime + if macro_variables.process is not None and not macro_variables.process.is_alive(): + # nothing should stop the process during runtime, if it has been started by + # the injector once raise AssertionError("the SharedDict manager is not running anymore") - macro_variables._stop() + if macro_variables.process is not None: + macro_variables._stop() join_children() - macro_variables._start() + macro_variables.start() if os.path.exists(tmp): shutil.rmtree(tmp) diff --git a/tests/testcases/test_injector.py b/tests/testcases/test_injector.py index 2121ae26..96a3f064 100644 --- a/tests/testcases/test_injector.py +++ b/tests/testcases/test_injector.py @@ -86,7 +86,7 @@ from tests.test import ( def wait_for_uinput_write(): start = time.time() if not uinput_write_history_pipe[0].poll(timeout=10): - raise AssertionError('No event written within 10 seconds') + raise AssertionError("No event written within 10 seconds") return float(time.time() - start) @@ -804,11 +804,15 @@ class TestInjector(unittest.IsolatedAsyncioTestCase): # in 5 more read-loop ticks, nothing new should have happened. # add a bit of a head-start of one EVENT_READ_TIMEOUT to avoid race-conditions # in tests - self.assertFalse(uinput_write_history_pipe[0].poll(timeout=EVENT_READ_TIMEOUT * 6)) + self.assertFalse( + uinput_write_history_pipe[0].poll(timeout=EVENT_READ_TIMEOUT * 6) + ) # 5 more and it should be within the second phase in which # the horizontal wheel is used. add some tolerance - self.assertAlmostEqual(wait_for_uinput_write(), EVENT_READ_TIMEOUT * 5, delta=EVENT_READ_TIMEOUT) + self.assertAlmostEqual( + wait_for_uinput_write(), EVENT_READ_TIMEOUT * 5, delta=EVENT_READ_TIMEOUT + ) event = uinput_write_history_pipe[0].recv() self.assertEqual(event.t, (EV_KEY, code_b, 1)) diff --git a/tests/testcases/test_ipc.py b/tests/testcases/test_ipc.py index 81b7a0b9..a502a5af 100644 --- a/tests/testcases/test_ipc.py +++ b/tests/testcases/test_ipc.py @@ -33,6 +33,7 @@ from tests.test import quick_cleanup class TestSharedDict(unittest.TestCase): def setUp(self): self.shared_dict = SharedDict() + self.shared_dict.start() time.sleep(0.02) def tearDown(self):