/glibcoro_examples

Examples of use of glibcoro

Primary LanguagePython

This repo contains examples of the use of **glibcoro**
([GitLab](https://gitlab.com/ldo/glibcoro),
[GitHub](https://github.com/ldo/glibcoro)), my module which makes the
GLib/GTK+ event loop compatible with Python’s
[`asyncio`](https://docs.python.org/3/library/asyncio.html) framework.

`animsort` -- this is a GUI-based app that produces a simple demonstration
of various sorting algorithms. I first wrote it many years ago, as an
exercise in learning GTK+. This version runs the sorting algorithm in a
coroutine, while the updating of the user interface happens concurrently.

`dbus_signal_listener` -- a listener for signals on
[D-Bus](https://www.freedesktop.org/wiki/Software/dbus/). Also requires
DBussy ([GitLab](https://gitlab.com/ldo/dbussy),
[GitHub](https://github.com/ldo/dbussy)), my Python binding for libdbus.

`hailstone_client`, `hailstone_server` -- a demonstration of client/server
communication over TCP/IP with multiple simultaneous connections.

`life` -- a program which runs John Horton Conway’s well-known “Life”
cellular-automata game. This version uses three separate coroutines:
one for running the user interface in “edit” mode, where the user can
make changes to the cell configuration, and two more that work
concurrently in “run” mode, one for progressing the generations by
applying the rules, while the other lets the user change the view of
the board and stop the run.

`pipes` -- an example of non-thread-blocking I/O with pipes: the parent
process waits for messages from child processes which can arrive in any
order, processing them as soon as they arrive.

`rocket_launch` -- this is a simple rocket-launch simulator, which prints
out a sequence of text messages indicating the progress of a launch: a
five-second countdown, followed by liftoff, followed by booster separation,
followed by achieving orbit. For added flavour, the program runs three
launches, starting at different times and overlapping their sequences,
to demonstrate event-loop-friendliness.

The `dbus_signal_listener`, `hailstone_client`, `hailstone_server`,
`pipes` and `rocket_launch` examples can work with either the
`glibcoro` event loop or the standard one provided by `asyncio`; by
default they use `glibcoro`’s `GLibEventLoop`, but if you define the
environment variable `USE_GLIB=0`, they will fall back to `asyncio`’s
default `BaseEventLoop`.

Lawrence D'Oliveiro <ldo@geek-central.gen.nz>
2018 December 29