Skip Menu |
 

This queue is for tickets about the Tcl CPAN distribution.

Report information
The Basics
Id: 77522
Status: resolved
Priority: 0/
Queue: Tcl

People
Owner: Nobody in particular
Requestors: abraxxa [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.02
Fixed in: (no value)



Subject: Tcl doesn't play nicely with forking
Download (untitled) / with headers
text/plain 830b
If an app using Tcl forks, the childs don't exit because Tcl::_Finalize is called in the END block. This little script demonstrates the problem: #!/usr/bin/env perl use strict; use warnings; use Parallel::Runner; use Tcl; #print "before finalize"; # that goes forward in time and kills $tcl before it even exists #Tcl::_Finalize; #print "after finalize"; my $tcl = Tcl->new; $tcl->Eval("puts {before the fork}"); my $runner = Parallel::Runner->new(2); $runner->run( sub { $tcl->Eval("puts {child $_}"); #POSIX::_exit(0); # this is one of the possible workarounds } ) for 1..3; $runner->finish; mst and Exodist helped me figure out what's going on and suggested the following fix: add this to the top of Tcl.pm: my $pid = $$; change the END block to: END { Tcl::_Finalize() if $$ == $pid; }
Download (untitled) / with headers
text/plain 282b
on 'MSWin32' this crashes even w/o printing what this should print: $tcl->Eval("puts {child $_}"); ...and pretty well on cygwin, though Generally, Perl multithreads are discouraged, so please do not expect for your script to work. Applied your changes to 1.26 :) thanks!
Thanks! Note that my code doesn't involve any threading but forking.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.