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
  • !189

Implement asyncio event loop based on glib

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Benjamin Berg requested to merge benzea/gio-asyncio into master Nov 23, 2021
  • Overview 5
  • Commits 9
  • Pipelines 17
  • Changes 16

This adds a simple asyncio event loop integration for GLib that only works on unix.

That said, I think it works really well:

  • Supports all python features; after all, it is the python standard selector mainloop
  • User can freely choose the GMainContext, setup works for any threads
  • get_event_loop returns a new loop if the thread has a main context
  • main context can be set by creating a loop and using set_event_loop; but only if there is no default one
    • Nested loops are possible, but setup must be done outside of the GLibEventLoopPolicy -> nested loop work theoretically, but asyncio can't deal with it
      • Only registered with GLibEventLoopPolicy if a default thread main context is pushed and t hen get_event_loop is run
      • Mainloop can also run without GLibEventLoopPolicy being aware of it
  • Correctly handles child watches (by using the python watcher; GLib child watches must not be used)

TODO:

  • Add more/better integration points
    • Overwrite SIGINT for the default main context
    • GApplication.run and similar
  • Add tests for GLib async function integration, i.e. test the !158 (closed) part
  • Add tests for nested main loops works, but python prevents it
  • Windows support? Should be reasonably simple now, but different. See below

On windows, we can't really register the events with GLib properly. But we could:

  • Subclass IocpProactor and have a custom GSource similar to Linux
  • In prepare:
    • If polling thread is running, we are done; just check if there are events ready
    • If polling thread is not running, call IocpProator._poll with 0 timeout directly to assess readyness
    • If not ready, start/poke polling thread
  • In polling thread:
    • call IocpProactor._poll with (almost) infinite timeout
    • when it returns, wakeup main context
    • wait for until being poked again by source
  • In check, just handle timeouts and grab event list
Edited Dec 27, 2021 by Benjamin Berg
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: benzea/gio-asyncio