One way to do it would be to fork off another process which would communicate to the parent through a socket and have the parent test the socket with select() in a repeat() event. Take a look at the code (untested snipets of an older app).

my $mw = MainWindow->new(); spawn_child(); $mw->repeat(100,\&read_child); sub read_child { my $rin = ""; vec($rin, fileno(CHILD), 1) = 1; my $err = $rin; for (0 .. 3) { # try to read from Child this many times before calli +ng it quits my ($nfound,$timeleft) = select($rin,undef,$err,0.001); print "$nfound." if ($debug > 1); while ($nfound) { # there is some data waiting to be read my $line = <CHILD>; ... ($nfound,$timeleft) = select($rin,undef,$err,0.0001); print ":$nfound" if ($debug > 1); } } print "\n" if ($debug > 1); } sub spawn_child { # parent process does only the GUI stuff all of the tester communica +tion # stuff hapens in the child only. The child sits around waiting for +the # parent to tell it to do something. The child does it, figures out +the # progress percentage, and informs the parent. The parent, upon rece +iving # this notification, update the GUI. socketpair(CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC); CHILD->autoflush(1); PARENT->autoflush(1); die unless defined($childPid=fork()); if ($childPid){ close PARENT; return; } # child process close CHILD; my $use_mfg_mode = 0; Loop: while(my $line = <PARENT>){ my $update = ""; print "received from parent: $line" if ($debug); print PARENT "progress: $update\n"; } print "Child is done!\n" if ($debug); exit(); }

In reply to Re: Perl/Tk and Threads by gri6507
in thread Perl/Tk and Threads by Streen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.