Skip to content

Use async/await for background tasks #3440

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

Merged
merged 17 commits into from
Nov 23, 2024
Merged

Use async/await for background tasks #3440

merged 17 commits into from
Nov 23, 2024

Conversation

amolenaar
Copy link
Member

@amolenaar amolenaar commented Aug 12, 2024

This PR explores the possibilities for async/await support that will be available in PyGObject 3.50.

asyncio is a common trait among Python developers. By moving from GLib idle handlers and callbacks to async/await we can lower the barrier for python devs to join.

PR Type

What kind of change does this PR introduce?

  • Bug fix
  • Feature
  • Chore (refactoring, formatting, local variables, other cleanup)
  • Documentation content changes

What is the current behavior?

We're using idle functions to schedule work in the background. How cool would it be if we can just submit async/await jobs?

Issue Number: https://gitlab.gnome.org/GNOME/pygobject/-/issues/636

What is the new behavior?

Explore how async/await can make our code more readable and possibly better testable.

Not sure if this will make it in main, but it's worth testing this new (experimental) functionality. We may come up with a few patterns that are useful for other PyGObject users.

Does this PR introduce a breaking change?

  • Yes
  • No

Async functions are introduced.

Other information

  • I tried to make everything async: open the file with aiofiles.open(), and await everything down to the XMLWriter. It works, but makes saving really slow. I'd rather have a fast save than a slow save with a progress bar.

@amolenaar amolenaar marked this pull request as draft August 12, 2024 10:34
@github-actions github-actions bot added the python Pull requests that update Python code label Aug 12, 2024
@amolenaar amolenaar force-pushed the async-support branch 2 times, most recently from faf00fc to 1b13f4f Compare October 6, 2024 12:29
@amolenaar amolenaar marked this pull request as ready for review October 6, 2024 12:30
@amolenaar amolenaar force-pushed the async-support branch 3 times, most recently from 5d1db2f to 434eac1 Compare October 6, 2024 12:54
@amolenaar amolenaar force-pushed the async-support branch 2 times, most recently from c53c79e to 0c5fc09 Compare October 19, 2024 15:06
@danyeaw
Copy link
Member

danyeaw commented Nov 18, 2024

Hi @amolenaar, this seems to work really well from my testing. Do you think we should try to merge this to main or make it configurable to turn on?

@amolenaar
Copy link
Member Author

@danyeaw I think we can merge this. There are some improvements we can implement once the next version of PyGObject is released.

@amolenaar amolenaar mentioned this pull request Nov 20, 2024
6 tasks
Copy link
Member

@danyeaw danyeaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amolenaar!

@danyeaw danyeaw merged commit f47d2b4 into main Nov 23, 2024
20 of 21 checks passed
@danyeaw danyeaw deleted the async-support branch November 23, 2024 20:26
@amolenaar
Copy link
Member Author

@danyeaw thanks for fixing the last bits.

@amolenaar amolenaar changed the title Async support Use async/await for background tasks Dec 10, 2024
@danyeaw danyeaw added feature A new feature and removed python Pull requests that update Python code labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants