Skip to main content

Trio guest mode wrapper for PyGTK

Project description


Build Status

Trio guest mode wrapper for PyGTK

Using the Trio guest mode feature, we can run both the Trio and PyGTK event loops alongside each other in a single program. This allows us to make use of the Trio library and the usual async/await syntax and not have to directly manage thread pools. This library provides a thin wrapper for initialising the guest mode and exposes a single public API function, into which you can pass your Trio main function.


$ pip install trio-gtk

Please note, trio-gtk does install pygobject directly as a Python package. We use relaxed bounds to ensure that the hard dependency on system packages (see cairo integration documentation will not stop you having a successful installation. This may not always work out. If you see a build error during your Pip installation, please raise a ticket and we will see what we can do.


import gi
import trio

gi.require_version("Gtk", "3.0")

from gi.repository import Gtk as gtk

import trio_gtk

class Example(gtk.Window):
    def __init__(self, nursery):
        gtk.Window.__init__(self, title="Example")

        self.button = gtk.Button(label="Create a task")
        self.button.connect("clicked", self.on_click)

        self.counter = 0
        self.nursery = nursery

        self.connect("destroy", gtk.main_quit)

    def on_click(self, widget):
        self.counter += 1
        self.nursery.start_soon(self.say_hi, self.counter)

    async def say_hi(self, count):
        while True:
            await trio.sleep(1)
            print(f"hi from task {count}")

async def main():
    async with trio.open_nursery() as nursery:
        await trio.sleep_forever()

Project details

Download files

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

Source Distribution

trio-gtk-3.0.0.tar.gz (15.3 kB view hashes)

Uploaded source

Built Distribution

trio_gtk-3.0.0-py3-none-any.whl (14.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page