Re: forked process exiting before output read

On 29/07/07, Jeffrey Ratcliffe <jeffrey ratcliffe gmail com> wrote:
That is an interesting idea I hadn't thought of. When I try it
(, I get

GLib-CRITICAL **: g_hash_table_foreach: assertion `hash_table != NULL'
failed at ./ line 23.

on launching the app. But it almost works! On hitting the start
button, it gets to 75% and then locks.

That last bit was not enough sleep. Now it works, but still gets the
GLib-CRITICAL error on launch, which I have no idea about.



use warnings;
use strict;
use threads;
use threads::shared;
use Thread::Semaphore;
use Gtk2 qw(-init -threads-init);
use Glib qw(TRUE FALSE);             # To get TRUE and FALSE

Glib::Object->set_threadsafe (TRUE);

my $semaphore = Thread::Semaphore->new(0);
my @queue:shared;
my $process:shared;
my $die:shared;
my $thread = threads->new(sub {
 while (TRUE) {
  last if $die;
  eval $process;

# Create the windows
my $window = Gtk2::Window->new('toplevel');
my $box = Gtk2::VBox->new;
my $pbar = Gtk2::ProgressBar->new;
my $buttonQuit = Gtk2::Button->new('Quit');
my $buttonStart = Gtk2::Button->new('Start');

$window->add ($box);
$box->add ($pbar);

# We should also link this to the destroy message on the main window,
# this is just quick and dirty
$buttonQuit->signal_connect(clicked => sub{Gtk2->main_quit});
$buttonStart->signal_connect(clicked => sub{
 $process = '
  my $n = 4;
  for (my $i = 0; $i <= $n; $i++) {
   push @queue, $i/$n;
   push @queue, "Running $i of $n";
 Glib::Timeout->add (200, sub{
  if (@queue) {
   my $fraction = shift @queue;
   my $text = shift @queue;
   return FALSE if ($fraction == 1);
  return TRUE;
$die = TRUE;

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