$window->signal_connect( delete_event=> sub { $die = 1; sleep 4; ## Give the thread a chance to end properly Gtk2->main_quit } );