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)

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): create asyncio duplicates of all servers methods and at the time, when we execute patched method, based on the current executor we either execute sync or async method. The same trick was also applied to our coverage/debugger tracer decorator and to the execution of pre_init_callback and post_init_callback.

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 server is everywhere for user function written with async kword.

I propose to throw DepricationWarning al the times, when we use old copied code. I do understand the level of verbosity, but this is exactly, what I want: I am afraid, that after next clean up (Python 13?) we won be able to run old code at all, so users will have to urgently re-write servers. Now they will have at least one year...

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