POE::Loop::Glib/Gtk2 trips over Wheel output
I'm trying to combine POE with a Gtk2 event loop, but it seems that this trips up POE, which then stops processing a wheel's output. Below is a simplified example, which starts a Gtk2 loop and a Run Wheel which counts to 1, but POE stops processing its output after 420 and then hangs (freezes GUI). Funny thing is, you can even throw out the Gtk GUI parts, and it still fails, as long as the "use Gtk2 '-init'" line is there. As soon as that's gone, POE processes everything correctly. Would be great if someone could comment on if I'm doing something weird. -- Mike Mike Schilli p...@perlmeister.com #!/usr/local/bin/perl -w use strict; use Gtk2 '-init'; use POE::Kernel { loop => "Glib" }; use POE::Session; use POE::Wheel::Run; use POE::Filter::Stream; POE::Session->create( inline_states => { _start => \&ui_start, play => \&play, out=> \&stdout_handler, }); $poe_kernel->run(); exit 0; ### sub ui_start { ### my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; $heap->{main_window} = Gtk2::Window->new ('toplevel'); $kernel->yield('play'); } ### sub play { ### my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; my $wheel = POE::Wheel::Run->new( Program => sub { print "$_\n" for 1..1; }, StdoutFilter => POE::Filter::Stream->new(), StderrEvent => 'out', StdoutEvent => 'out', ); $heap->{player} = $wheel; } ### sub stdout_handler { ### my ($heap, $input, $wheel_id) = @_[HEAP, ARG0, ARG1]; print STDERR "$input\n"; }
Re: POE::Loop::Glib/Gtk2 trips over Wheel output
I believe you may have encountered a known bug with a simple solution. https://rt.cpan.org/Public/Bug/Display.html?id=53302 Now if only we could somehow get that patch released -- Rocco Caputo - rcap...@pobox.com On Mar 9, 2010, at 03:10, p...@perlmeister.com wrote: I'm trying to combine POE with a Gtk2 event loop, but it seems that this trips up POE, which then stops processing a wheel's output. Below is a simplified example, which starts a Gtk2 loop and a Run Wheel which counts to 1, but POE stops processing its output after 420 and then hangs (freezes GUI). Funny thing is, you can even throw out the Gtk GUI parts, and it still fails, as long as the "use Gtk2 '-init'" line is there. As soon as that's gone, POE processes everything correctly. Would be great if someone could comment on if I'm doing something weird. -- Mike Mike Schilli p...@perlmeister.com #!/usr/local/bin/perl -w use strict; use Gtk2 '-init'; use POE::Kernel { loop => "Glib" }; use POE::Session; use POE::Wheel::Run; use POE::Filter::Stream; POE::Session->create( inline_states => { _start => \&ui_start, play => \&play, out=> \&stdout_handler, }); $poe_kernel->run(); exit 0; ### sub ui_start { ### my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; $heap->{main_window} = Gtk2::Window->new ('toplevel'); $kernel->yield('play'); } ### sub play { ### my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; my $wheel = POE::Wheel::Run->new( Program => sub { print "$_\n" for 1..1; }, StdoutFilter => POE::Filter::Stream->new(), StderrEvent => 'out', StdoutEvent => 'out', ); $heap->{player} = $wheel; } ### sub stdout_handler { ### my ($heap, $input, $wheel_id) = @_[HEAP, ARG0, ARG1]; print STDERR "$input\n"; }
Re: POE::Loop::Glib/Gtk2 trips over Wheel output
On Tue, 9 Mar 2010, Rocco Caputo wrote: I believe you may have encountered a known bug with a simple solution. https://rt.cpan.org/Public/Bug/Display.html?id=53302 Now if only we could somehow get that patch released Is the solution to be applied to POE itself or POE::Loop::Glib? Anything I can do from 'userland'? -- Mike Mike Schilli m...@perlmeister.com -- Rocco Caputo - rcap...@pobox.com On Mar 9, 2010, at 03:10, p...@perlmeister.com wrote: I'm trying to combine POE with a Gtk2 event loop, but it seems that this trips up POE, which then stops processing a wheel's output. Below is a simplified example, which starts a Gtk2 loop and a Run Wheel which counts to 1, but POE stops processing its output after 420 and then hangs (freezes GUI). Funny thing is, you can even throw out the Gtk GUI parts, and it still fails, as long as the "use Gtk2 '-init'" line is there. As soon as that's gone, POE processes everything correctly. Would be great if someone could comment on if I'm doing something weird. -- Mike Mike Schilli p...@perlmeister.com #!/usr/local/bin/perl -w use strict; use Gtk2 '-init'; use POE::Kernel { loop => "Glib" }; use POE::Session; use POE::Wheel::Run; use POE::Filter::Stream; POE::Session->create( inline_states => { _start => \&ui_start, play => \&play, out=> \&stdout_handler, }); $poe_kernel->run(); exit 0; ### sub ui_start { ### my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; $heap->{main_window} = Gtk2::Window->new ('toplevel'); $kernel->yield('play'); } ### sub play { ### my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; my $wheel = POE::Wheel::Run->new( Program => sub { print "$_\n" for 1..1; }, StdoutFilter => POE::Filter::Stream->new(), StderrEvent => 'out', StdoutEvent => 'out', ); $heap->{player} = $wheel; } ### sub stdout_handler { ### my ($heap, $input, $wheel_id) = @_[HEAP, ARG0, ARG1]; print STDERR "$input\n"; }
Re: POE::Loop::Glib/Gtk2 trips over Wheel output
On Mar 9, 2010, at 11:59, Mike Schilli wrote: On Tue, 9 Mar 2010, Rocco Caputo wrote: I believe you may have encountered a known bug with a simple solution. https://rt.cpan.org/Public/Bug/Display.html?id=53302 Now if only we could somehow get that patch released Is the solution to be applied to POE itself or POE::Loop::Glib? Anything I can do from 'userland'? If it's the right solution, it's to be applied to POE::Loop::Glib. There's not much to be done from userland, except maybe to ask the author to apply and release the change. Maybe the author would like a co-maintainer? -- Rocco Caputo - rcap...@pobox.com On Mar 9, 2010, at 03:10, p...@perlmeister.com wrote: I'm trying to combine POE with a Gtk2 event loop, but it seems that this trips up POE, which then stops processing a wheel's output. Below is a simplified example, which starts a Gtk2 loop and a Run Wheel which counts to 1, but POE stops processing its output after 420 and then hangs (freezes GUI). Funny thing is, you can even throw out the Gtk GUI parts, and it still fails, as long as the "use Gtk2 '-init'" line is there. As soon as that's gone, POE processes everything correctly. Would be great if someone could comment on if I'm doing something weird. -- Mike Mike Schilli p...@perlmeister.com #!/usr/local/bin/perl -w use strict; use Gtk2 '-init'; use POE::Kernel { loop => "Glib" }; use POE::Session; use POE::Wheel::Run; use POE::Filter::Stream; POE::Session->create( inline_states => { _start => \&ui_start, play => \&play, out=> \&stdout_handler, }); $poe_kernel->run(); exit 0; ### sub ui_start { ### my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; $heap->{main_window} = Gtk2::Window->new ('toplevel'); $kernel->yield('play'); } ### sub play { ### my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP]; my $wheel = POE::Wheel::Run->new( Program => sub { print "$_\n" for 1..1; }, StdoutFilter => POE::Filter::Stream->new(), StderrEvent => 'out', StdoutEvent => 'out', ); $heap->{player} = $wheel; } ### sub stdout_handler { ### my ($heap, $input, $wheel_id) = @_[HEAP, ARG0, ARG1]; print STDERR "$input\n"; }
Session lifetime issue (post on behalf of)
I'm trying to solve a common problem which occurs when I'm using PoCos. The crux of the issue is that a session doing a post to a PoCo, needs to stay alive for work done by a secondary post by that PoCo. Consider: 1. Session A posts to Session B 2. In Session B event handler, it posts to Session C "on behalf of Session A". 3. Session B exits event handler. 4. Session A dies, because it's event was handled by B, but it has no way of knowing Session C is doing something for it. Since Session B typically belongs to the "other persons PoCo" (OPPC), I can't really get inside of it and change it. So the solution to this problem must not alter the code for the OPPC. This seems to be a very common second order problem. Is there some standard technique for solving this? I've looked at few PoCos for solutions, and searched for "continuation" like things (e.g. POE::Session::Yield::CC), but these don't seem to solve the problem. Thanks, Zerohero
Re: Session lifetime issue (post on behalf of)
On Tue, 9 Mar 2010 09:59:30 -0800 Zero Hero wrote: > I'm trying to solve a common problem which occurs when I'm using > PoCos. The crux of the issue is that a session doing a post to a > PoCo, needs to stay alive for work done by a secondary post by that > PoCo. > > Consider: > 1. Session A posts to Session B > 2. In Session B event handler, it posts to Session C "on behalf of > Session A". > 3. Session B exits event handler. > 4. Session A dies, because it's event was handled by B, but it > has no way of knowing Session C is doing something for it. > > Since Session B typically belongs to the "other persons PoCo" (OPPC), > I can't really get inside of > it and change it. So the solution to this problem must not alter the > code for the OPPC. > > This seems to be a very common second order problem. > > Is there some standard technique for solving this? I've looked at few > PoCos for solutions, and > searched for "continuation" like things (e.g. > POE::Session::Yield::CC), but these don't seem to > solve the problem. > > Thanks, > > Zerohero Typically what you can do is in Session B, increment the reference count for Session A (access via $_[+SENDER]) until after Session C notifies Session B that it's work is complete. Then you can decrement again. The other thing you could do is set up Session A to be persistent in some fashion, such as polling a shared result queue, where Session C will ultimately dump the result. -- Nicholas Perez XMPP/Email: n...@nickandperla.net http://search.cpan.org/~nperez/ http://github.com/nperez