Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deltachat-rpc-client: get rid of asyncio #4787

Merged
merged 1 commit into from
Oct 5, 2023
Merged

Conversation

link2xt
Copy link
Collaborator

@link2xt link2xt commented Oct 4, 2023

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 of async and await 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 with pytest-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 because readline() 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 moment aiohttp is broken and I had to revert CI to 3.11 in #4776.

This change replaces asyncio with threading and enables pytest-xdist for deltachat-rpc-client. Most of the changes are in the reworked rpc.py and adapting the tests. The rest is the removal of async and await.

For most bots migration to new API is as simple as removing asyncio loop and all await keywords before Delta Chat API calls. For bots using asyncio libraries, they can keep asyncio loop and call now blocking functions with asyncio.to_thread from async functions.

@link2xt link2xt changed the base branch from master to stable October 4, 2023 22:02
@link2xt link2xt force-pushed the link2xt/rpc-client-sync branch 3 times, most recently from c374da3 to def80a0 Compare October 5, 2023 00:58
@link2xt link2xt force-pushed the link2xt/rpc-client-sync branch 2 times, most recently from cb67b45 to 12f8d52 Compare October 5, 2023 03:25
@link2xt link2xt marked this pull request as ready for review October 5, 2023 03:25
@link2xt link2xt force-pushed the link2xt/rpc-client-sync branch 2 times, most recently from a55480b to 46c6f2d Compare October 5, 2023 05:54
@link2xt link2xt requested a review from adbenitez October 5, 2023 08:23
@adbenitez
Copy link
Member

maybe now I can try to port simplebot to the new bindings :)

@link2xt link2xt force-pushed the link2xt/rpc-client-sync branch 2 times, most recently from 1bf47e8 to 482e121 Compare October 5, 2023 12:25
@link2xt
Copy link
Collaborator Author

link2xt commented Oct 5, 2023

maybe now I can try to port simplebot to the new bindings :)

First step would be porting existing https://github.com/deltachat-bot/faqbot and its dependency https://github.com/deltachat-bot/deltabot-cli-py I thought.

@link2xt
Copy link
Collaborator Author

link2xt commented Oct 5, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants