#197 Not running the SharedDict for macros in key-mapper-control

xkb
sezanzeb 3 years ago
parent 320fd37ca7
commit e13780a208

@ -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"""

@ -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")

@ -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)

@ -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))

@ -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):

Loading…
Cancel
Save