http://qs321.pair.com?node_id=1058275


in reply to Perl tk gui hangs when large data thrown to it

G'day ghosh123,

"I can not put the entire code here, but i am putting some snippets of it to explain you better :"

Please post a minimal example which reproduces your problem. Creating such an example will often highlight the problem and possibly even present a solution.

Putting bits of code here doesn't really help. For instance, I could say that "[ \&checkData, $self, $server, $readable_handles ]" is problematic because "sub checkData { ... }" doesn't accept any arguments. I have no way of knowing whether that subroutine really doesn't accept any arguments or if that was just some of the code you chose to omit.

"It also using Tk's repeat to continuously check whether any data has arrived to update the gui."

Tk::fileevent is probably a more appropriate tool for this task.

-- Ken

Replies are listed 'Best First'.
Re^2: Perl tk gui hangs when large data thrown to it
by ghosh123 (Monk) on Oct 15, 2013 at 12:06 UTC

    I am just including a very very simplified code which is just one perl file only. Please change the repeat frequency to test it. The gui would show better performance if the repeat frequency is increased to 1sec , currently it is 1ms only.
    My requirement is :

    1. what is the reason for the gui to get hung when we are trying to change some 100 rows on it every 1 ms . Can not perl tk handle this ? is this a limitation ?

    2. is their any other mechanism to make it work, provided i will repeat it every 1 ms and would try to change 100 rows of it randomly.

    use Tk; use Tk::HList; use Time::HiRes qw/usleep/; my $mw = MainWindow->new(); my $hlistframe = $mw->Frame()->pack( -fill => 'both', -expand => 1 ); my $font = "{helvetica} -12 bold"; my $hl = $hlistframe->Scrolled( 'HList', -scrollbars => 'ose', -columns => 7, -header => 1, #-height => 10, -width => 50, -command => sub { print "test\n"; }, )->pack( -fill => 'both', -expand => 1 ); my $num = $hl->Label( -text => "Number", -anchor => 'w', -font => $fon +t ); $hl->headerCreate( 0, -itemtype => 'window', -widget => $num ); my $name = $hl->Label( -text => "ID", -anchor => 'w', -font => $font ) +; $hl->headerCreate( 1, -itemtype => 'window', -widget => $name ); my $DOB = $hl->Label( -text => "Job", -anchor => 'w', -font => $font ) +; $hl->headerCreate( 2, -itemtype => 'window', -widget => $DOB ); my $Address = $hl->Label( -text => "status", -anchor => 'w', -font => +$font ); $hl->headerCreate( 3, -itemtype => 'window', -widget => $Address ); my $style1 = $hl->ItemStyle( 'text', -selectforeground => 'black', -anchor => 'nw', -background => 'green', -font => $font ); my $style2 = $hl->ItemStyle( 'text', -selectforeground => 'black', -anchor => 'nw', -background => 'red', -font => $font ); my $style3 = $hl->ItemStyle( 'text', -selectforeground => 'black', -anchor => 'nw', -background => 'blue', -font => $font ); sub populate { my $path = 0; foreach my $entry ( 1 .. 100 ) { insertData( $path, $entry ); $path++; } } &populate(); sub insertData { my ( $path, $entry ) = @_; $hl->add($path); # print "path $path \n"; $hl->itemCreate( $path, 0, -text => "$path" ); # , -style => $ +style1); $hl->itemCreate( $path, 1, -text => "someid" ); # , -style => $ +style1); $hl->itemCreate( $path, 2, -text => "test" ); #, -style => $s +tyle1); $hl->itemCreate( $path, 3, -text => "running", -style => $style1 ) +; } $mw->repeat( 1, \&changeItem ); my $flag; sub changeItem { my %flag; foreach ( 1 .. 100 ) { my $randRow = int( rand(20) ); print "randRow $randRow \n"; if ( $flag{$randRow} ) { $hl->itemConfigure( $randRow, 3, -text => "pending", -style => $style2 ); $hl->itemConfigure( $randRow, 3, -text => "waiting", -style => $style2 ); $flag{$randRow} = 0; print "if flag ", $flag{$randRow}, "\n"; } else { print "else flag 0\n"; $hl->itemConfigure( $randRow, 3, -text => "finished", -style => $style3 ); $hl->itemConfigure( $randRow, 3, -text => "aborted", -style => $style3 ); $flag{$randRow} = 1; print "else flag ", $flag{$randRow}, " \n"; } #usleep(100); #sleep 2 ; } } MainLoop;
Re^2: Perl tk gui hangs when large data thrown to it
by ghosh123 (Monk) on Oct 15, 2013 at 11:02 UTC
    is there any place where i can put some sample code. even the sample code require 5-6 module files to be included for the gui, server and client.

      No, not a minimal example of your full application; just a minimal code example to reproduce your problem. As I already stated, this exercise will often highlight the problem and possibly present a solution.

      I see you've made more than one reply to a single response (in at least two places). Furthermore, more than one of those replies are either very close or exact duplicates. "How do I change/delete my post?" explains how to include additional information in a post you've already made. Repeatedly posting the same (long) nodes will only annoy people; it's unlikely to get you better answers. "What shortcuts can I use for linking to other information?" shows, among other things, how to link to information you've already provided in another node.

      -- Ken