#107 fixed autoload

xkb
sezanzeb 3 years ago committed by sezanzeb
parent 0395c06093
commit 36b96935c6

@ -361,11 +361,8 @@ class Daemon:
logger.error('No presets configured to autoload')
return
for device_key, _ in autoload_presets:
group = groups.find(key=device_key)
if group is None:
continue
self._autoload(group.key)
for group_key, _ in autoload_presets:
self._autoload(group_key)
def start_injecting(self, group_key, preset):
"""Start injecting the preset for the device.

@ -432,7 +432,7 @@ class Injector(multiprocessing.Process):
events, so ideally they should be copied from source.
"""
logger.debug(
'Started consumer to inject to %s, fd %s',
'Started consumer to inject for %s, fd %s',
source.path, source.fd
)

@ -62,6 +62,10 @@ class SharedDict:
atexit.register(self._stop)
self._start()
# To avoid blocking forever if something goes wrong. The maximum
# observed time communication takes was 0.001 for me on a slow pc
self._timeout = 0.02
def _start(self):
"""Ensure the process to manage the dictionary is running."""
if self.process is not None and self.process.is_alive():
@ -99,10 +103,10 @@ class SharedDict:
"""Get a value from the dictionary."""
return self.__getitem__(key)
def is_alive(self):
def is_alive(self, timeout=None):
"""Check if the manager process is running."""
self.pipe[1].send(('ping',))
select.select([self.pipe[1]], [], [], 0.1)
select.select([self.pipe[1]], [], [], timeout or self._timeout)
if self.pipe[1].poll():
return self.pipe[1].recv() == 'pong'
@ -114,11 +118,7 @@ class SharedDict:
def __getitem__(self, key):
self.pipe[1].send(('get', key))
# To avoid blocking forever if something goes wrong.
# The maximum observed time this takes was 0.001 for me on a slow pc
timeout = 0.02
select.select([self.pipe[1]], [], [], timeout)
select.select([self.pipe[1]], [], [], self._timeout)
if self.pipe[1].poll():
return self.pipe[1].recv()

@ -559,6 +559,9 @@ def quick_cleanup(log=True):
for task in asyncio.all_tasks():
task.cancel()
if not macro_variables.process.is_alive():
raise AssertionError('the SharedDict manager is not running anymore')
macro_variables._stop()
join_children()
@ -579,9 +582,6 @@ def quick_cleanup(log=True):
clear_write_history()
if not macro_variables.process.is_alive():
raise AssertionError('the SharedDict manager is not running anymore')
for name in list(uinputs.keys()):
del uinputs[name]
@ -606,7 +606,7 @@ def quick_cleanup(log=True):
for _, pipe in pending_events.values():
assert not pipe.poll()
assert macro_variables.is_alive()
assert macro_variables.is_alive(1)
def cleanup():

@ -475,6 +475,29 @@ class TestDaemon(unittest.TestCase):
self.assertEqual(len(history), 1)
self.assertEqual(history[group.key][1], preset)
def test_autoload_3(self):
# based on a bug
preset = 'preset7'
group = groups.find(key='Foo Device 2')
mapping = Mapping()
mapping.change(Key(3, 2, 1), 'a')
mapping.save(group.get_preset_path(preset))
config.set_autoload_preset(group.key, preset)
config.save_config()
self.daemon = Daemon()
self.daemon.set_config_dir(get_config_path())
groups.set_groups([])
self.daemon.autoload()
# it should try to refresh the groups because one of the
# group_keys is unknown at the moment
history = self.daemon.autoload_history._autoload_history
self.assertEqual(history[group.key][1], preset)
self.assertEqual(self.daemon.get_state(group.key), STARTING)
if __name__ == "__main__":
unittest.main()

Loading…
Cancel
Save