Re: Async Callbacks w/Python 3 + Gtk3
- From: Marius Gedminas <marius gedmin as>
- To: gtk-app-devel-list gnome org
- Subject: Re: Async Callbacks w/Python 3 + Gtk3
- Date: Tue, 18 Dec 2018 17:36:56 +0200
On Mon, Dec 17, 2018 at 04:09:27PM -0500, Adam Tauno Williams wrote:
I'm rebuilding an old application in Python3+Gtk.
The applications makes calls to remote services which I'd like to have
be asynchronous. I've search around the interwebz and found a wide
variety of answers to this question [Gtk.mainloop + async(other-
loop?)]; almost all of them are pretty old.
Is there an "official" / endorsed / classical way to handle this?
None of the "official" HOWTOs I have found address this - - - unless I
have missed one [entirley possible]
There are two main approaches:
- use async APIs that integrate with the glib main loop
(e.g. Gio has classes for talking to sockets/subprocesses, which is
low level, then there's Soap that gives you a higher level async HTTP
wrappers.)
- use threads, being very careful never to call GTK+ APIs from them
directly (use GLib.idle_add() to register callbacks to be executed
from the main thread, whenever a background thread does something
interesting that needs to be reflected in the UI).
https://wiki.gnome.org/Projects/PyGObject/Threading has examples of
both threads and using Goo.File.load_contents_async() to download a
file over HTTP asyncronously.
HTH,
Marius Gedminas
--
PCMCIA - People Can't Memorize Computer Industry Acronyms
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]