Skip Menu |

This queue is for tickets about the Wx-Perl-ProcessStream CPAN distribution.

Report information
The Basics
Id: 68635
Status: open
Priority: 0/
Queue: Wx-Perl-ProcessStream

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.30
Fixed in: (no value)



Subject: increasing ghost events, if more than one wxapp
create wxapp, destroy wxapp create second wxApp, stdout/stdout is repeated two times create third wxApp, stdout/stdout is repeated three times create fourth wxApp, stdout/stdout is repeated four times .... not good :) not good :) not good :) not good :)
Subject: wxProcessStreamEcho.pl
#!/usr/bin/perl -- use strict; use warnings; use Wx 0.99 ; Main( @ARGV ); exit( 0 ); sub Main { Fain() for 1 .. 6; } sub Fain { my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new(undef,-1,"", [21,21+ rand(5)] ); my $text = Wx::TextCtrl->new( $frame, -1, "", Wx::wxDefaultPosition(), Wx::wxDefaultSize(), Wx::wxTE_MULTILINE() | Wx::wxTE_READONLY() | Wx::wxHSCROLL() | Wx::wxNO_BORDER() ); Wx::Log::SetActiveTarget( Wx::LogTextCtrl->new( $text ) ); $frame->Show(1); $app->SetTopWindow($frame); $app->{frame} = $frame; $app->{text} = $text; use Wx::Perl::ProcessStream qw( :everything ); EVT_WXP_PROCESS_STREAM_STDERR ( $app, \&evt_process_stderr_stdout ); EVT_WXP_PROCESS_STREAM_STDOUT ( $app, \&evt_process_stderr_stdout ); EVT_WXP_PROCESS_STREAM_EXIT ( $app, \&evt_process_exit ); { my $cmd = ['perl','-le', ' $f=gmtime; print $f; warn $f; warn $$; ' ]; my $process = Wx::Perl::ProcessStream::Process->new( $cmd, join(' ','[',@$cmd,']'), $app, )->Run; } $app->MainLoop; } use Wx::Perl::Carp qw' warn '; sub evt_process_exit { my ($self, $event) = @_; $event->Skip(1); my $exitcode = ''; my $procname = ''; eval { $exitcode = $event->GetProcess->GetExitCode(); $procname = $event->GetProcess->GetProcessName(); $event->GetProcess->Destroy; 1; } or warn $@; my $apptext = qq(EXIT: $procname: $exitcode\n); $self->{text}->AppendText($apptext); return; } sub evt_process_stderr_stdout { my ($self, $event) = @_; $event->Skip(1); # allow event to be processed by further handlers my $procname = $event->GetProcess->GetProcessName(); my $line = $event->GetLine; my $apptext = ''; my @stdout = @{ $event->GetProcess->GetStdOutBuffer }; my @stderr = @{ $event->GetProcess->GetStdErrBuffer }; $apptext .= qq($line\n); $self->{text}->AppendText($apptext); return; }
Hi, You can't have more than one wxapp - you are just creating multiple references to the same thing. You are therefore connecting multiple event handlers to the same wxapp. In the event handlers you do $event->Skip(1) so all your handlers get called for each event. Hope this helps. Mark
Subject: increasing ghost events, if more than one wxapp (warn/document)
On Fri Jun 03 20:38:10 2011, MDOOTSON wrote: Show quoted text
> Hi, > > You can't have more than one wxapp - you are just creating multiple > references to the same thing.
Thanks. I'm sure I knew this at one point. I tried $app->{alreadyInitialized} = 1; this crashes perl. So, a warning would be really helpful. Also, mentioning this in Wx.pm would also be helpful Thanks Show quoted text
> > You are therefore connecting multiple event handlers to the same wxapp. > > In the event handlers you do $event->Skip(1) so all your handlers get > called for each event.
In the documentation you connect to $self. I originally I tried to connected to $frame, but that didn't work. So, I have a few thoughts 1. change docs to connect to $app 2. warn when EVT_WXP_PROCESS_STREAM_STDERR called more than once 3. change code to also accept only coderef and use wxTheApp and change docs to show only this new usage, but support both EVT_WXP_PROCESS_STREAM_STDERR( \&evt_process_stderr ); Show quoted text
> > Hope this helps. > > Mark
It did, thanks a lot :) I hope my new suggestions turn this into a resolved instead of rejected :D
Hi, On Sat Jun 04 23:06:46 2011, noreply wrote: Show quoted text
> I tried > > $app->{alreadyInitialized} = 1; > > this crashes perl. > So, a warning would be really helpful. > Also, mentioning this in Wx.pm would also be helpful > Thanks
You would need to show an example of how the crash occurs. I guess that would be an item for the Wx module. Show quoted text
> In the documentation you connect to $self. > I originally I tried to connected to $frame, but that didn't work. > So, I have a few thoughts > 1. change docs to connect to $app
Connecting to a Wx::Frame ( or any other Wx::EvtHandler ) works fine as far as I know. Have you got an example where it does not work? All the tests use a Wx::Frame. Show quoted text
> 2. warn when EVT_WXP_PROCESS_STREAM_STDERR called more than once
EVT_WXP_PROCESS_STREAM_STDERR might be called more than once on the same event handler for valid reasons and there are also various other ways you could connect an event handler to events. I don't see how I might implement a useful warning, seeing as there is no way I can work out if you intentionally connected twice. Show quoted text
> 3. change code to also accept only coderef and use wxTheApp > and change docs to show only this new usage, but support both > > EVT_WXP_PROCESS_STREAM_STDERR( \&evt_process_stderr );
It uses standard Wx event connection so it accepts whatever Wx accepts. e.g. $coderef, \&evt_sub, sub { mycode }, 'SubName' etc. I assume you only wrote 'limit to wxTheApp' thinking that is the only event handler that works? Show quoted text
> It did, thanks a lot :) > I hope my new suggestions turn this into a resolved instead of
rejected Show quoted text
> :D
Well, I marked it as rejected as I couldn't see a bug or anything I might change or fix. However, if you want this open then I'll leave it as open. Regards Mark
On Sun Jun 05 00:03:21 2011, MDOOTSON wrote: Show quoted text
> You would need to show an example of how the crash occurs. > I guess that would be an item for the Wx module.
I will open a separate report in Wx Thanks Show quoted text
> Connecting to a Wx::Frame ( or any other Wx::EvtHandler ) works fine as > far as I know. Have you got an example where it does not work? All the > tests use a Wx::Frame.
... Show quoted text
> I assume you only wrote 'limit to wxTheApp' thinking that is the only > event handler that works? >
Yup, thats why I wrote that. I've attached an example. Connecting to frame works, but no event handlers get called. It is only when I connect to a wxApp that event handlers fire. This lead me to believe they only work with wxapp. Thanks
Subject: wxProcessStreamEchoFrame.pl
#!/usr/bin/perl -- use strict; use warnings; use Wx 0.99 ; our $Fain; Main( @ARGV ); exit( 0 ); sub Main { Fain() for 1 .. 6; } sub Fain { my $app = Wx::SimpleApp->new; my $frame = Wx::Frame->new(undef,-1,"", [21,21+ rand(5)] ); my $text = Wx::TextCtrl->new( $frame, -1, "", Wx::wxDefaultPosition(), Wx::wxDefaultSize(), Wx::wxTE_MULTILINE() | Wx::wxTE_READONLY() | Wx::wxHSCROLL() | Wx::wxNO_BORDER() ); Wx::Log::SetActiveTarget( Wx::LogTextCtrl->new( $text ) ); $frame->Show(1); $app->SetTopWindow($frame); $frame->{text} = $text; $app->{text} = $text; use Wx::Perl::ProcessStream qw( :everything ); my $FrameOrApp = rand(2) > 1 ? $frame : $app ; warn "FrameOrApp $FrameOrApp "; EVT_WXP_PROCESS_STREAM_STDERR ( $FrameOrApp, \&evt_process_stderr_stdout ); EVT_WXP_PROCESS_STREAM_STDOUT ( $FrameOrApp, \&evt_process_stderr_stdout ); EVT_WXP_PROCESS_STREAM_EXIT ( $FrameOrApp, \&evt_process_exit ); { my $cmd = ['perl','-le', ' $f=gmtime; print $f; warn $f; warn $$; ' ]; my $process = Wx::Perl::ProcessStream::Process->new( $cmd, join(' ','[',@$cmd,']'), $app, )->Run; } $app->MainLoop; } use Wx::Perl::Carp qw' warn '; sub evt_process_exit { my ($self, $event) = @_; $event->Skip(1); my $exitcode = ''; my $procname = ''; eval { $exitcode = $event->GetProcess->GetExitCode(); $procname = $event->GetProcess->GetProcessName(); $event->GetProcess->Destroy; 1; } or warn $@; my $apptext = qq(EXIT: $procname: $exitcode\n); $self->{text}->AppendText($apptext); return; } sub evt_process_stderr_stdout { my ($self, $event) = @_; $event->Skip(1); # allow event to be processed by further handlers my $procname = $event->GetProcess->GetProcessName(); my $line = $event->GetLine; my $apptext = ''; my @stdout = @{ $event->GetProcess->GetStdOutBuffer }; my @stderr = @{ $event->GetProcess->GetStdErrBuffer }; $apptext .= qq($line\n); $self->{text}->AppendText($apptext); return; }
Subject: Re: [rt.cpan.org #68635] increasing ghost events, if more than one wxapp
Date: Sun, 05 Jun 2011 13:23:28 +0100
To: bug-Wx-Perl-ProcessStream [...] rt.cpan.org
From: Mark Dootson <mark.dootson [...] znix.com>
Hi, my $process = Wx::Perl::ProcessStream::Process->new( $cmd, join(' ','[',@$cmd,']'), $frameorapp, )->Run; You need to pass the appropriate eventhandler recipient. On 05/06/2011 11:11, noreply via RT wrote: Show quoted text
> Queue: Wx-Perl-ProcessStream > Ticket<URL: https://rt.cpan.org/Ticket/Display.html?id=68635> > > On Sun Jun 05 00:03:21 2011, MDOOTSON wrote: > >
>> You would need to show an example of how the crash occurs. >> I guess that would be an item for the Wx module.
> > I will open a separate report in Wx > Thanks > >
>> Connecting to a Wx::Frame ( or any other Wx::EvtHandler ) works fine as >> far as I know. Have you got an example where it does not work? All the >> tests use a Wx::Frame.
> ...
>> I assume you only wrote 'limit to wxTheApp' thinking that is the only >> event handler that works? >>
> Yup, thats why I wrote that. > I've attached an example. > Connecting to frame works, but no event handlers get called. > It is only when I connect to a wxApp that event handlers fire. > This lead me to believe they only work with wxapp. > > Thanks >