Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • pygobject pygobject
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 303
    • Issues 303
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GNOMEGNOME
  • pygobjectpygobject
  • Merge requests
  • !158

Return asyncio awaitable object for Gio async routines

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Benjamin Berg requested to merge wip/gio-async-awaitable-return into master Nov 12, 2020
  • Overview 4
  • Commits 4
  • Pipelines 16
  • Changes 9

Features/Notes:

  • If no callback is given, an awaitable object is returned
  • If cancellable is given, this will be used, otherwise one will be created implicitly
  • user_data will be ignored if callback is not set
  • If *_finish throws an exception, and the result is not fetched a message will be logged.

TODO:

  • Add a asyncio mainloop implementation. Thinking of https://github.com/jhenstridge/asyncio-glib/pull/10
  • Refuse Async creation for non-GLib mainloops (otherwise we leak Async objects in mass)

How it works:

  • During function cache creation, async routines are detected, this means:

    • One callback of type GAsyncReadyCallback which has a closure that is GI_SCOPE_TYPE_ASYNC
    • A single cancellable parameter
    • No return/out values
    • A _finish function exists (type is not checked, but I think that is acceptable as it will raise an exception when called).
    • Save information in GIIntrospection
  • If during argument dispatch, we find that the GI_SCOPE_TYPE_ASYNC callback on such a function has not been provided, we:

    • Create a new PyGIAsync instance, and keep it in the scope to return
    • Retrieve the cancellable argument
    • Pass PyGIAsync instance as user_data and set specific callback
  • PyGIAsync instance implements awaitable protocol, with the following caveats/differences:

    • In python, a cancellation means the future is done immediately. This will not be the case for PyGIAsync, we will always wait for the callback method to be called.
    • Right now iteration isn't quite correct; this is only relevant when the API is used incorrectly in ways that make no sense
Edited Jul 12, 2021 by Benjamin Berg
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: wip/gio-async-awaitable-return