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

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"; } }

Replies are listed 'Best First'.
Re^5: Perl/Tk problem on Windows
by eserte (Deacon) on Jun 03, 2004 at 11:53 UTC
    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.
      Yeah I guess I'll try something like that if I don't find any answers here. Thanx a lot for trying. I assumed that since the example was in an O'Reilly book it would work, but then they probably weren't thinking of Windows when they put it in :)
Re^5: Perl/Tk problem on Windows
by Ven'Tatsu (Deacon) on Jun 03, 2004 at 14:28 UTC
    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.
      That settles it. I think I better nix this approach and use threads, as both you and eserte have suggested. Thnx
        If you get it to work using threads I will be interested in learning how. I have tried fork and threads with Tk and the only thing that kind of works is when you fork in such a way that you never manipulate a widget within the child. To communicate with the parent I use a pair of pipes. I would give POE a shot if you are not successful with threads.