async_gui
async_gui is a library aimed to make use of threads in GUI applications simpler. It’s inspired by PyCon talk Using futures for async GUI programming in Python 3.3 and tornado @gen.engine implementation.
Most of GUI toolkits don’t allow you to access graphical elements from non-GUI thread. Python 3.2+ has nice new feature concurrent.futures, but we can’t just wait for result from future and callbacks are not very handy.
Combination of Coroutines via Enhanced Generators (PEP-342) and futures creates a rich and easy to use asynchronous programming model which can be used for creating highly responsive GUI applications.
Example
Demo of button click handler:
@engine.async
def on_button_click(self, *args):
self.status_label.setText("Downloading image...")
# Run single task in separate thread
image_data = yield Task(self.load_url,
"http://www.google.com/images/srpr/logo4w.png")
pixmap = QtGui.QPixmap.fromImage(QtGui.QImage.fromData(image_data))
self.image_label.setPixmap(pixmap)
self.status_label.setText("Downloading pages...")
urls = ['http://www.google.com',
'http://www.yandex.ru',
'http://www.python.org']
# Run multiple task simultaneously in thread pool
pages = yield [Task(self.load_url, url) for url in urls]
self.status_label.setText("Done")
avg_size = sum(map(len, pages)) / len(pages)
self.result_label.setText("Average page size: %s" % avg_size)
Tasks yielded from on_button_click() executed in thread pool, but GUI updates done in the GUI thread. For CPU-bound applications there is also ability to run tasks in pool of processes.
See full example in examples directory.
Features
Installation
Using pip:
$ pip install async_gui
Or download, unpack and:
$ python setup.py install
To run tests use:
$ python setup.py test
Links
Documentation at readthedocs.org
Source code and issue tracking at GitHub.
History
0.2.0 (2013-0x-xx)
MultiTask can return generator of ready tasks instead waiting for all done
0.1.0 (2013-04-06)
initial PyPI release
Metadata
Release files for async_gui 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| async_gui-0.1.1.tar.gz | 22.0 kB | Without provenance | Details for async_gui-0.1.1.tar.gz |
Release files / async_gui-0.1.1.tar.gz
| Download URL | async_gui-0.1.1.tar.gz |
|---|---|
| Size | 22.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1584c18f4363bb48a0d8ced1a83387e5b5e7a3779ead018258938560a9317af4
|
|
BLAKE2b-256 checksum How to use checksums |
656a7ed68f2a3e49c6c616482a3f5024c1f8568000a19bc9c656b5a38747c2a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for async_gui 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.