#! /usr/bin/env python

import gc
import gio
import glib

def test_func_closure():
    def make_cancellable():
        cancellable = gio.Cancellable()
        def on_cancelled(*args):
            # Just test the variable is still bound.
            cancellable
        cancellable.connect('cancelled', on_cancelled)
        return cancellable

    x = make_cancellable()
    x.push_current()
    del x

    gc.collect()

    loop = glib.MainLoop()

    glib.idle_add(lambda: gio.cancellable_get_current().cancel())
    glib.idle_add(lambda: loop.quit())

    loop.run()


test_func_closure()
