Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

POE, pTk, JSON Cause Lockup with perlapp

by cmv (Chaplain)
on Oct 21, 2008 at 04:00 UTC ( [id://718366]=perlquestion: print w/replies, xml ) Need Help??

cmv has asked for the wisdom of the Perl Monks concerning the following question:

Update: This problem has a similar solution to another problem posted, and the solution can be found here.

Hi Monks-

Here is a strange problem. The perl application listed below works fine for me, with the supplied data under windows XP (32-bit) with activestate perl 5.8.7. However, if I build an executable using perlapp, and run it on the same data, windows reports that the program stops responding, and I can't scroll, nor will the stop button work).

In addition, using poe_main_window doesn't work (see where I commented "WHY DO I HAVE TO DO THIS?").

If I take the JSON stuff out, the scrolling & stop button work, and it seems to run ok.

Any thoughts or help is much appreciated!

Thanks

-Craig

Here is the perlapp command line:

perlapp --add "POE::Wheel" --add "POE::Loop::Select" --add "POE::Resou +rce::Aliases" --add "POE::Resource::Events" --add "POE::Resource::Ext +refs" --add "POE::Resource::FileHandles" --add "POE::Resource::SIDs" +--add "POE::Resource::Sessions" --add "POE::Resource::Signals" --add +"POE::Resource::Statistics" --verbose --clean --force --lib lib --exe + analyze.exe display.pl

Here is the data for the input file:

{"Text":["Hi there...","How are you?","1","2","3","4","5","6","7","8", +"9","10","11","12","13","14","15","16","17","18","19","20","21","22", +"23","24","24","26","27","28","29"]}

Here is the script:

use strict; use warnings; use Tk; # This MUST come before use POE... use POE; use POE::Component::Client::TCP; use POE::Filter::Stream; use POE::Wheel::FollowTail; use Data::Dumper; use JSON::XS; # Setup input file (if any)... my $infile = shift || die "Missing Input File..."; _displayData(); # Setup data processing... my $sess = _processData($infile); # This should simply create a dummy postback on the tail session my $subref = $sess->postback('DontDie'); # Go... print STDERR "STARTING to process data...\n"; POE::Kernel->run; exit; sub _processData{ my $ifile=shift || die "Missing input file"; POE::Session->create( inline_states=>{ _start=>sub { print "Session ", $_[SESSION]->ID, " has started.\n"; $_[KERNEL]->alias_set("myClient"); my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; $_[HEAP]->{wheel}=POE::Wheel::FollowTail->new( Seek=>0, Filename=>$ifile, InputEvent=>'display', ); }, display => sub{ InputEvent=>$_[KERNEL]->post(Display=>data=>$_[ARG0]), }, sendStop => sub{ print "Stopping file input\n"; my $heap = $_[HEAP]; delete $heap->{wheel}; }, }, ), } sub _displayData{ my $hwid = shift; my $text; my $json=new JSON::XS; $json=$json->ascii([1]); POE::Session->create( inline_states => { _start => sub { $_[KERNEL]->alias_set("Display"); my $kernel=$_[KERNEL]; # WHY DO I HAVE TO DO THIS???? my $top = $poe_main_window || MainWindow->new(); #my $top = $poe_main_window; # Create Stop button... $top->Button(-text=>"Stop", -command=>sub{ &stop($kernel); $top->update; } )->pack(-side=>'bottom'); # Create top level Tree... $text = $top->Scrolled('Text', -scrollbars=>'osow')-> pack(-fill=>'both', -side=>'left', -expand=>1); }, data=>sub{ my $input=$_[ARG0] || return; my $node=$json->decode($input); my $txt = join("\n", @{$node->{Text}}); $text->insert('end', $txt); $text->update; }, }); } sub stop{ my $ker = shift; if ($ker){ print STDERR "Sending sendStop to myClient\n"; $ker->call("myClient","sendStop"); } }

Replies are listed 'Best First'.
Re: POE, pTk, JSON Cause Lockup with perlapp
by rcaputo (Chaplain) on Oct 21, 2008 at 04:43 UTC

    Creating your own MainWindow is an odd workaround. $poe_main_window should be defined there, so your MainWindow->new() call should never happen.

    If you do succeed in creating your own MainWindow, you may notice that clicking on the close button doesn't stop your program. You can re-enable this with POE::Kernel's signal_ui_destroy() method.

    There's no good reason for JSON::XS to interfere with Tk, but perhaps there's something conflicting at the XS level. Have you tried a non-complied JSON library instead?

    If it is a C-level issue, then also be sure that you're deploying the software on a compatible version of Windows and C's runtime libraries. I'm not sure whether perlapp bundles things that far down.

      rcaputo++ As always, thanks for your quick and knowledgable replies.

      I've made available a zip file containing the perlapp binary that I generated on my windows machine from the above program, along with a copy of the input file. You can download it for the next few days from here. On a side note, is there some way I can upload this to the perlmonks website to keep it available with this node?

      On my machine the input data shows up in the text window, but the program becomes unresponsive as soon as all the data has been placed there. If I use a really big file, I can hit the stop button and it will work (even though I'm using MainWindow->new), but then the program becomes unresponsive. Also, scrolling works while the input is being read in.

      I agree with your statement Creating your own MainWindow is an odd workaround, however I had to do this to get the perlapp-ed program to run. The value of $poe_main_window in the perlapp-ed program is null. On top of that, if I force MainWindow to be used by changing the line to be my $top = MainWindow->new(); Running the .pl script creates 2 visible windows (one blank, the other with text) while the perlapp-ed program creates only the one with the text.

      I will try using some other JSON modules and see if that has any effect.

      Thanks for the suggestions!

      -Craig

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://718366]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found