https://github.com/virtuald/pygi-gio-coroutines
Make asynchronous I/O using PyGObject+Gio easier!
https://github.com/virtuald/pygi-gio-coroutines
Last synced: about 1 month ago
JSON representation
Make asynchronous I/O using PyGObject+Gio easier!
- Host: GitHub
- URL: https://github.com/virtuald/pygi-gio-coroutines
- Owner: virtuald
- License: lgpl-2.1
- Created: 2015-11-01T19:05:03.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-02T05:40:39.000Z (over 10 years ago)
- Last Synced: 2025-03-21T15:43:23.688Z (over 1 year ago)
- Language: Python
- Size: 141 KB
- Stars: 1
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
pygi-gio-coroutines
===================
This is a prototype for a single-file library that allows you to integrate
python coroutines with Gio's asynchronous operations. Gio provides a lot of
asynchronous I/O support, but they're a bit clunky to use and this makes it
a little easier to chain I/O operations together.
This implementation was developed for the `Exaile audio player `_
to help us as we move to GTK3. I'm still feeling this out to see what bugs
come up, so please provide feedback!
There's a lot of features that could be added to such a project. I've added
things that are useful for me now, feel free to add your own. Some ideas:
* Transparent support for cancellation
* Cancellation of I/O
* Cancellation of the coroutine
Usage
=====
.. code:: python
from gio_coroutines import gio_coroutine, async, idle, Return
@gio_coroutine
def lots_of_io():
..
# Async write operation
result = yield async(f, 'write', bytes, 0, None)
..
# Delay execution via GLib.idle_add
yield idle
# return some value
raise Return('val')
def on_done(r):
try:
retval = r.result()
except:
logger.exception("Some bad thing happened")
lots_of_io(on_done=on_done)
Requirements
============
* PyGObject + Gio
Installation
============
This project is easily installed via pip:
pip install pygi-gio-coroutines
Author
======
Dustin Spicuzza (dustin@virtualroadside.com)
Portions of the code were inspired by Tornado's coroutine + futures
implementation.
License
=======
LGPL 2.1+ (Same as PyGI)