On Thu, Dec 30, 2004 at 20:09:57 -0500, muppet wrote:
On Dec 30, 2004, at 4:42 PM, Jan Hudec wrote:I just ran across an incompatible change in signal handling in perl 5.7.3 and later, that causes problems when the Glib::MainLoop is running. The problem is, that the new signal handling stuff defers execution of the perl hooks until a "safe" place -- which never happens when a Gtk::MainLoop sits in a poll. Please consider adding a custom event handler (the poll is broken by the signal, so it should run) to dispatch these handlers.I thought i'd made a faq entry about this, but obviously i'm just imagining things again. I've got to stop that. Google says: http://mail.gnome.org/archives/gtk-perl-list/2004-February/msg00111.html This problem has existed with all versions of gtk2-perl, because we only work with perl >= 5.8.0. Here's something from one of my apps that needs to have special SIGINT handling at certain times. It uses a heartbeat timer only when the INT handler is installed, to avoid unnecessary load. my $signal_watcher; sub set_up_interrupt_handling { $SIG{INT} = \&my_special_int_handler; $signal_watcher = Glib::Timeout->add (100, sub {TRUE}); } sub tear_down_interrupt_handling { delete $SIG{INT}; Glib::Source->remove ($signal_watcher); }
Ouch, that's ugly :-(. I just solved it with POSIX::sigaction, which does not try to be clever. But I meant something like this: gboolean _prepare(GSource *self, gint *timeout) { timeout = -1; return FALSE; } gboolean _check(GSource *self) { return signal_pending; } gboolean _dispatch(GSource *self) { process_signals(); return TRUE; } GSourceFuns sigfuns = {_prepare, _check, _dispatch, NULL}; GSource *sighandler = g_source_new(&sigfuns, sizeof(GSource)); g_source_attach(sighandler, NULL); That is, just add a special source, that will be checked in every iteration, it will look at the signal flag in perl interpreter and if it's set, it will just make a dummy call to the interpreter to let it handle the signal. Minimal overhead and no need to hack about with %SIG and things like that. This option was not mentioned in the message cited above. ------------------------------------------------------------------------------- Jan 'Bulb' Hudec <bulb ucw cz>
Attachment:
signature.asc
Description: Digital signature