deltachat-rpc-client: get rid of asyncio #4787
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
asyncio
seems to be a bad choice for new Python bindings. There are several reasons for this. It requires users to learn how to start asyncio loop in their application. Code is full ofasync
andawait
keywords, which simply add noise, most of the changes in this PR are the result of mechanical removal of these keywords. Garbage-collected tasks are automatically cancelled, unlike threads, which is a well-known footgun but is unavoidable for new asyncio users.pytest-asyncio
is not compatible withpytest-xdist
, making it impossible to run tests in parallel. There are subtle differences to the rest of the standard library for I/O, recent issue #4782 actually broke faqbot becausereadline()
in asyncio fails on too long lines. With the upcoming GIL removal in Python 3.12 and following versions, I expect more asyncio packages to break, at the momentaiohttp
is broken and I had to revert CI to 3.11 in #4776.This change replaces
asyncio
withthreading
and enablespytest-xdist
fordeltachat-rpc-client
. Most of the changes are in the reworkedrpc.py
and adapting the tests. The rest is the removal ofasync
andawait
.For most bots migration to new API is as simple as removing
asyncio
loop and allawait
keywords before Delta Chat API calls. For bots usingasyncio
libraries, they can keepasyncio
loop and call now blocking functions withasyncio.to_thread
fromasync
functions.