Skip to main content

GLib event loop integration for asyncio

Project description

GLib event loop integration for asyncio

This module provides a Python 3 asyncio event loop implementation that makes use of the GLib event loop. This allows for mixing of asyncio and some GLib based code within the same thread.

Enabling this event loop can be achieved with the following code:

import asyncio
import asyncio_glib

At this point, asyncio.get_event_loop() will return a GLibEventLoop.

Implementation strategy

To ease maintenance, I have tried to reuse as much of the standard library asyncio code as possible. To this end, I created a GLib implementation of the selectors.BaseSelector API. Combine this with the existing asyncio.SelectorEventLoop class, and we have our event loop implementation.

To test that the event loop is functional, I have reused parts of the standard library test suite to run against the new selector and event loop.

At present the selector sublcasses the private selectors._BaseSelectorImpl class, which is a potential source of future compatibility problems. If that happens, taking a local copy of that code is an option.

Comparison with Gbulb

Gbulb is another implementation of the asyncio event loop on top of GLib. The main differences are:

  • Gbulb dispatches asyncio callbacks directly from the GLib main loop. In contrast, asyncio-glib iterates the GLib main loop until an asyncio event is ready and then has asyncio event loop dispatch the event.

  • Gbulb has some Windows compatibility code, while asyncio-glib has had no testing on that platform.

  • asyncio-glib is an essentially unmodified SelectorEventLoop, so should automatically gain any features from new Python releases.

The asyncio-glib code base is also about one tenth of the size of Gbulb.

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for asyncio-glib, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size asyncio_glib-0.1-py3-none-any.whl (13.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size asyncio-glib-0.1.tar.gz (13.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page