Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

POE::Wheel::Run & MSWin32 problem

by cmv (Chaplain)
on Aug 10, 2009 at 16:25 UTC ( #787371=perlquestion: print w/replies, xml ) Need Help??
cmv has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks-

The attached POE program works as expected under both Unix and Windows. By that I mean that the current directory is listed in the Tk window, and the Tk window stays up after the directory listing is done.

However, you may notice that in order to make it work under windows, I'm running the command dir & pause. This is because if I simply run the dir command, the whole program exits and the Tk window goes away (I want the Tk window to hang around until the user does something to make it go away).

Why is this? I put the postback('DontDie') line in there for preserving the Tk window, and it works under Unix. The postback will also work under windows when I'm not using POE::Wheel::Run to do the directory listing under a separate process. I'm guessing that adding the pause keeps the child process around, which is not really what I want to do. Is there a way to preserve the Tk window without keeping the child around?

Any thoughts or pointers is appreciated.



use English; use strict; use warnings; use Tk; use POE; use POE::Wheel::Run; # Setup program to run... my $PGM = 'ls'; if ($OSNAME eq 'MSWin32') { $PGM = 'dir & pause' }; #if ($OSNAME eq 'MSWin32') { $PGM = 'dir' }; # This doesn't work! print STDERR "$OSNAME PGM=$PGM\n"; my $TEXT; # Global for text widget... # Setup POE session... my $session = _poeSetup(); # Create dummy postback so the session won't die once input is done... my $subref = $session->postback('DontDie'); # Go... $poe_kernel->run(); ################# # POE Subroutines ################# sub _poeSetup { my $session = POE::Session->create( inline_states=>{ _start => \&_startUp, KidOut => \&_GetStdout, KidErr => \&_GetStderr, KidClose => \&_DoClose, }, ); return($session); } # POE Session Supporting Routines... sub _startUp { $TEXT=$poe_main_window->Scrolled('Text', -wrap=>'none')->pack; $poe_main_window->update; my $child = POE::Wheel::Run->new( Program => $PGM, StdoutEvent => 'KidOut', StderrEvent => 'KidErr', CloseEvent => 'KidClose', ); $_[KERNEL]->sig_child($child->PID, '_DoSig'); $_[HEAP]{Kids}{WID}{$child->ID} = $child; $_[HEAP]{Kids}{PID}{$child->PID} = $child; } sub _GetStdout { my ($line, $wid) = @_[ARG0, ARG1]; my $child = $_[HEAP]{Kids}{WID}{$wid}; $TEXT->insert('end', $child->PID . " OUT: $line\n"); $TEXT->see('end'); $poe_main_window->update; } sub _GetStderr { my ($line, $wid) = @_[ARG0, ARG1]; my $child = $_[HEAP]{Kids}{WID}{$wid}; $TEXT->insert('end', $child->PID . " ERR: $line\n"); $TEXT->see('end'); $poe_main_window->update; } sub _DoClose { my $wid = $_[ARG0]; my $child = $_[HEAP]{Kids}{WID}{$wid}; unless (defined $child) { print STDERR "wid $wid closed all pipes.\n"; return; } print STDERR "wid $wid closed all pipes.\n"; delete $_[HEAP]{Kids}{PID}{$child->PID}; } sub _DoSig { print STDERR "pid $_[ARG1] exited with status $_[ARG2].\n"; my $child = delete $_[HEAP]{Kids}{PID}{$_[ARG1]}; return unless defined $child; delete $_[HEAP]{Kids}{WID}{$child->ID}; }

Replies are listed 'Best First'.
Re: POE::Wheel::Run & MSWin32 problem
by rcaputo (Chaplain) on Aug 11, 2009 at 03:11 UTC
      Using POE::Wheel::Run::Win32 seems to cause various errors to occur, but the most prominent is:

      ERR: Free to wrong pool 3558130 not 235f40 at c:/Perl/lib/Tk/ line 86.

      Update: rcaputo++
      I have opened a ticket as you have asked. Many thanks!

        This sounds like a bug in POE::Wheel::Run and/or POE::Wheel::Run::Win32, which isn't surprising as I haven't had access to a good Win32 machine until recently.

        It could also be a problem with Tk and forking, which is really threading in Windows. Tk may be shutting down when one thread stops. To Tk it may look as if the program is done. I'm not sure, but I'll have some time to find out soon.

        Please open a ticket at POE's queue at, and attach your test program. It will help me track and prioritize this issue. I'll also ping Chris Williams (the author of POE::Wheel::Run::Win32) on IRC to see if he knows something about it.

        Thank you.

Re: POE::Wheel::Run & MSWin32 problem
by rcaputo (Chaplain) on Aug 26, 2009 at 06:08 UTC

    The problem is not just that the Tk window goes away. PERL.EXE crashes outright. I have isolated the problem to a conflict between Tk and fork() when $^O eq "MSWin32". This short example crashes the same way:

    use Tk; my $mw = Tk::MainWindow->new(); sleep 1 if fork (); exit;

    Unfortunately, until we can get Tk and fork() and MSWin32 working together, I'm afraid there's probably nothing that POE can do to help. has a less concise discussion.

Re: POE::Wheel::Run & MSWin32 problem
by roboticus (Chancellor) on Aug 26, 2009 at 10:40 UTC

    I'd suggest that rather than shelling out to a command window, you just read the directory entries yourself. I don't know if it will solve your problem or not, but it may be a simple way out of your dilemma.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://787371]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2017-12-16 13:30 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (453 votes). Check out past polls.