in reply to Re: Perl/Tk problem on Windows
in thread Perl/Tk problem on Windows

Tried this. It still don't work. Am I missing something fundamental ? I tried changing the code to the below version, but to the same end.
sub client_connect { my ( $ns, $from ) = @_; chomp($_=<$ns>); print "$from : $_\n"; my $mw = MainWindow->new(); my $t= $mw->Scrolled('Text'); $t->pack(-expand => 1, -fill => 'both' ); tie ( *TEXT, 'Tk::Text', $t ); print TEXT "$from\n\n$_\n"; $mw->destroy; close $ns; CORE::exit(); }

Replies are listed 'Best First'.
Re^3: Perl/Tk problem on Windows
by eserte (Deacon) on Jun 03, 2004 at 10:22 UTC
    Are you using fork or threads?
      I'm using fork.
      while ( my $ns = $server->accept ) { ... if ( my $pid = fork ) { close $ns or die "Client socket close failed. [$!]\n"; } elsif (defined $pid) { $ns->autoflush(1); client_connect $ns,$from; } else { die "fork error. [$!]\n"; } }
        There were posts from other people with similar problems when using Tk together with fork on Windows. Maybe it's better to use Tk operations only in the main thread and use some kind of IPC between the child and parent.
        I'm suprised you just got Free to wrong pool errors. fork() ususaly causes crashes in my experiance.
        Tk is not thread safe, and since fork() on windows is emulated with ithreads perl tends to choke and die.
        You could use threads and only call Tk from one thread as the other poster sugests, that is usualy safe.