threads and trayicon error

2008-09-29 Thread anguila
I'm writing a code that check if there is any news my universiti website.
And for that I use 2 scripts. The first one (cvNews.pl) check if there is
any new and if it finds show a dialog with that info. and if not, return
error.
The other script is the trayicon applet. If I can get access into the site,
it shows the online-icon but if  I can't connect or I'm not connected to
any network, shows the offline-icon.
I have a funtion that update the state of the image in the trayicon, that
use 2 threads. This function works, and does that supposed to do, but after
some time the trayicon image doesn't show very well... the image that it
shows is only some lines about that image, the image isn't complete.

I use 2 threads, the first one, execute the cvnews.pl to get the news, and
the second wait $wait_time_error (the time acces to get the info from the
web) to join the first thread for update the trayicon online or offline.

(...)
my $pic = Gtk2::Image-new_from_file($logo);
my $eventbox = Gtk2::EventBox-new;
$eventbox-add($pic);
my $icon= Gtk2::TrayIcon-new('trayicon');

$icon-add($eventbox);
$icon-signal_connect ('button-release-event'= \click);
(...)
my $wait_time_error=10;
sub update_ico {

my $avisar=shift;
my $thread_ico = threads-new(sub {
if ($avisar) {
open (IN,perl $dir/cvNews.pl -avisar 21 |);
}
else {
open (IN,perl $dir/cvNews.pl 21 |);
}
foreach (IN){
if ($_ =~/Error/){
1;
}
}
close IN;
0;
});
my $thread_idle= threads-new(sub {
sleep($wait_time_error); # Temps d'espera a que cvNews retorni algo
i poder aixi recuperar el thread
my $err=$thread_ico-join();# ja que si el recuperava
inmediatament després és com si no executes cap thread.
if ($err){
$pic-set_from_file($logo_off);
#   print Logo off!\n;
}
else {
#  print Logo on!\n;
$pic-set_from_file($logo);
}
1;
});
return 1;
}

Any idea what is happening? Why it works and after crash? Sometimes return
those errors... sometimes no..:

Buscant novetats...!
Buscant novetats...!

GLib-GObject-CRITICAL **: g_object_get_qdata: assertion `G_IS_OBJECT
(object)' failed during global destruction.
Gtk-CRITICAL **: gtk_container_foreach: assertion `GTK_IS_CONTAINER
(container)' failed during global destruction.
GLib-GObject-CRITICAL **: g_object_set_qdata: assertion `G_IS_OBJECT
(object)' failed during global destruction.
GLib-GObject-CRITICAL **: g_object_set_qdata: assertion `G_IS_OBJECT
(object)' failed during global destruction.
GLib-GObject-CRITICAL **: g_object_set_qdata: assertion `G_IS_OBJECT
(object)' failed during global destruction.
GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)'
failed during global destruction.
GLib-GObject-WARNING **: instance with invalid (NULL) class pointer during
global destruction.
GLib-GObject-CRITICAL **: g_signal_handlers_destroy: assertion
`G_TYPE_CHECK_INSTANCE (instance)' failed during global destruction.
GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)'
failed during global destruction.
GLib-GObject-WARNING **: instance with invalid (NULL) class pointer during
global destruction.
GLib-GObject-CRITICAL **: g_signal_handlers_destroy: assertion
`G_TYPE_CHECK_INSTANCE (instance)' failed during global destruction.
GLib-GObject-WARNING **: instance with invalid (NULL) class pointer during
global destruction.
GLib-GObject-CRITICAL **: g_signal_handlers_destroy: assertion
`G_TYPE_CHECK_INSTANCE (instance)' failed during global destruction.
Scalars leaked: -1
GLib-GObject-CRITICAL **: g_object_get_qdata: assertion `G_IS_OBJECT
(object)' failed at ./AppletcvNews.pl line 105.
GLib-GObject-CRITICAL **: g_object_get_qdata: assertion `G_IS_OBJECT
(object)' failed at ./AppletcvNews.pl line 106.
GLib-GObject-CRITICAL **: g_object_get_qdata: assertion `G_IS_OBJECT
(object)' failed at ./AppletcvNews.pl line 106.
GLib-GObject-CRITICAL **: g_object_get_qdata: assertion `G_IS_OBJECT
(object)' failed at ./AppletcvNews.pl line 106.
Segmentation fault



Thanks!

David.
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: threads and trayicon error

2008-09-29 Thread Jeffrey Ratcliffe
2008/9/29 anguila [EMAIL PROTECTED]:
 I'm writing a code that check if there is any news my universiti website.

Why don't you use Specto? http://specto.sourceforge.net

Jeff
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: threads and trayicon error

2008-09-29 Thread anguila
Because I wrote this applet for example to another code that I'm writing.. i
try to get work the easy script first and then use that in a biggest code..
anyway, I'll check that web :)

But... any idea why it not works?

On Mon, Sep 29, 2008 at 11:17 PM, Jeffrey Ratcliffe 
[EMAIL PROTECTED] wrote:

 2008/9/29 anguila [EMAIL PROTECTED]:
  I'm writing a code that check if there is any news my universiti website.

 Why don't you use Specto? http://specto.sourceforge.net

 Jeff

___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: threads and trayicon error

2008-09-29 Thread Jörn Reder
anguila wrote:

 I use 2 threads, the first one, execute the cvnews.pl to get the news, and
 the second wait $wait_time_error (the time acces to get the info from the
 web) to join the first thread for update the trayicon online or offline.

I'd suggest not using threads for this purpose... too complicated and 
error-prone. It's not allowed to call Gtk+ functions outside the thread
which started the main loop, so you need to start a pure worker thread 
communicating with the main thread to update the GUI etc.

You already have a separate process for the http stuff, so it's easy to
install an I/O watcher on your pipe and response to the events instead 
of struggling with threads.

That's very common and you find an example for this in Gtk Perl docs, 
e.g. here:

  
http://live.gnome.org/GTK2-Perl/FrequentlyAskedQuestions#head-20b1c1d3a92f0c61515cb88d15e06b686eba6cbc

  [ 18. How do I keep my GUI updating while doing a long file read? ]

Regards,

Jörn

-- 
Think before you code. And while you're doing it probably won't hurt. ;)


pgpiP8P4r7Jru.pgp
Description: PGP signature
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list


Re: threads and trayicon error

2008-09-29 Thread anguila
so the mistake in my code is use threads?I thought that maybe I used bad
some function :\ I will try with this way (mentioned in the gtk2-perl faq),
but it's weird that the trayicon changes good and after X (unknow) time
crash and this icon becomes a line :\ with any reason


2008/9/30 Jörn Reder [EMAIL PROTECTED]

 anguila wrote:

  I use 2 threads, the first one, execute the cvnews.pl to get the news,
 and
  the second wait $wait_time_error (the time acces to get the info from the
  web) to join the first thread for update the trayicon online or offline.

 I'd suggest not using threads for this purpose... too complicated and
 error-prone. It's not allowed to call Gtk+ functions outside the thread
 which started the main loop, so you need to start a pure worker thread
 communicating with the main thread to update the GUI etc.

 You already have a separate process for the http stuff, so it's easy to
 install an I/O watcher on your pipe and response to the events instead
 of struggling with threads.

 That's very common and you find an example for this in Gtk Perl docs,
 e.g. here:


 http://live.gnome.org/GTK2-Perl/FrequentlyAskedQuestions#head-20b1c1d3a92f0c61515cb88d15e06b686eba6cbc

  [ 18. How do I keep my GUI updating while doing a long file read? ]

 Regards,

 Jörn

 --
 Think before you code. And while you're doing it probably won't hurt. ;)

 ___
 gtk-perl-list mailing list
 gtk-perl-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/gtk-perl-list


___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list