Skip to content

New Asyncio servers implementation

Yury Matveyev requested to merge new_asyncio_server_implementation into develop

Related to the !618 (merged) and !577 (merged)

Closes #572 (closed)

Current implementation of green_modes utilizes the basic sync PyTango code and tries to convert in on the fly to async. The main advantage of such implementation is simple code maintaining: all changes we make automatically applied to all green modes. However, especially with Asyncio there is a major problem: to convert all original sync method we uses asyncio.coroutine function, which was the first iteration to make coroutines by asyncio. But the method was deprecated in 3.8 and already removed from Python 3.11. As the solution we copied old code to PyTango. But then cleaning process of Asyncio library continued and for Python 3.12 we had to copy run_coroutine_threadsafe and modify it to be able to work with such legacy generator-based coroutines. However, there is no guarantee, that our copied methods will be compatible with new versions of Asyncio or any other methods will fail to work.

After some consideration I found, that the original idea to split Device into two classes: Device and AsyncioDevice is complicated and not really helpful, since we will have also to duplicate all other functionality: wrapping with executors, tracers, set_value etc.

I found that it is much easier to extend the solution we made in !564 (merged), but in a different way: at the time, when we execute patched method, we either execute method directly, or use additional async helper, which does all syncronious calls in asyncio thread executor. We aslo split our coverage/debugger tracer decorator, as well as pre_init_callback and post_init_callback to sync and async and select the proper one on the fly, based on current worker.

The asyncio executor was modified to skip legacy code in case it is asked to execute coroutine function. In case of sync function old code still executed, so old servers should be able to work.

As far as our test covers all cases - we do not execute legacy code anymore if all user functions in server are written with async kword.

The old way to run asycnio servers (with sync methods, converted on runtime) is marked as depricated, and, most probably will be removed from pytango 11.

PS And I also made a change in pyproject, that now all warnings are not allowed for tests to pass

Edited by Yury Matveyev

Merge request reports