Skip to content

Asyncio server doesn't change state to ALARM with AttrQuality

Closes #525 (closed)

The reason is that AsyncioExecutor.execute() makes a coroutine out of the dev_state function, running in the server's asynco loop. This function, in turn, calls read_attr_hardware, always_executed_hook and reads all attributes (if they have an alarm property defined, and are not polled). These functions are also sent to the AsyncioExecutor.execute(), but in this time they are just scheduled into loop, but never awaited.

To solve it I propose to move dev_state to separate thread with the help of standart asyncio.to_thread method, is that case AsyncioExecutor.execute will schedule and await all sub-calls. The main problem here is that we cannot put any asynco methods in the original implementation of the dev_state, since it is synchronous and only at runtime covered to coroutine (and this is one of the reason why utilizing asynco.coroutine() is deprecated since py3.4). But we can have two dev_state functions: sync and async. Unfortunately we cannot decide at startup which one we need since executor is changed after server was created, so we select the proper one at the runtime, when the function is called. Surprisingly, all this works :-)

BUT: this works only with py >=3.9. This is OK only, if we accept our new version policy ...

Edited by Yury Matveyev

Merge request reports