-
-
Notifications
You must be signed in to change notification settings - Fork 216
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
Conversation
7741723
to
9b28037
Compare
ddee4f9
to
23e7ff4
Compare
faf00fc
to
1b13f4f
Compare
5d1db2f
to
434eac1
Compare
c53c79e
to
0c5fc09
Compare
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? |
@danyeaw I think we can merge this. There are some improvements we can implement once the next version of PyGObject is released. |
This makes for more ideomatic Python.
Also model merge is async now.
There are a few other places where this dialog is used, but those I have not checked.
Default sleep in seconds (as a float).
This way it's easier to manage their lifecycles (e.i. cancel them if the service exits).
This removes the last use of g_async from Gaphor's code.
0c5fc09
to
c20f9a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @amolenaar!
@danyeaw thanks for fixing the last bits. |
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?
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?
Async functions are introduced.
Other information
aiofiles.open()
, and await everything down to theXMLWriter
. It works, but makes saving really slow. I'd rather have a fast save than a slow save with a progress bar.