Glib::IO->add_watch not uninstalling

A user running FreeBSD has reported a bug that I can't personally
reproduce in my gtk2-perl application. With his help, however, I have
distilled it down to the attached demo. He reports that the progress
bar pulses for three seconds, then CPU usage goes up to 100% and stays

I take it, therefore, that the Glib::IO->add_watch call isn't
uninstalling itself properly. On my Ubuntu Edgy and Red Hat boxes, it
runs OK, i.e. after pressing the button, the progress bar pulses for
three seconds and then stops. Am I doing something wrong? Or is there
some problem with Glib::IO->add_watch under FreeBSD?

In the real application, the Glib::IO->add_watch call obviously reads
the output of a piped command without blocking.

Grateful for any help



use warnings;
use strict;
use Gtk2 -init;
use Glib qw(TRUE FALSE);             # To get TRUE and FALSE

my $window = new Gtk2::Window;
my $vb = new Gtk2::VBox(0, 0);

my $b = new Gtk2::Button('Pulse');

$window->signal_connect('destroy', sub {Gtk2->main_quit});

# Set up ProgressBar
my $pbar = Gtk2::ProgressBar->new;
$pbar -> set_pulse_step(.1);

$b->signal_connect('clicked', sub {
 my $running = TRUE;

# Timer will run until callback returns false
 my $timer = Glib::Timeout->add (100, sub { if ($running) {
                                             return TRUE;
                                            else {
                                             return FALSE;
                                            } });

 my $cmd = "sleep 3";

# Interface to frontend
 my $pid = open my $read, '-|', $cmd or die "can't open pipe: $!";

# Read without blocking
 Glib::IO->add_watch ( fileno($read), ['in', 'hup'], sub {
  my ($fileno, $condition) = @_;
  if ($condition eq 'hup') {
   close $read;
   $running = FALSE;
   return FALSE;  # uninstall
  my $line;
  sysread $read, $line, 1024;
  return TRUE;  # continue without uninstalling




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]