For Event, the child will inherit the timers. This is not a problem though since you do not want the child to return control back to Event.
So at the end of the work done in the child, you exit. You can unloop before or after the child does its work too ... though I agree it does not seem clear from the Event docs what this buys you or whether it is preferred.
If you 'return' at the end of the child, with no unlooping, you end up with 2 event loops running and the same configured watchers. If you unloop, you continue from after where you called Event::loop.
Some code to illustrate the idea:
1 #!/usr/bin/perl 2 3 use strict; 4 use warnings; 5 6 use Event; 7 use POSIX ":sys_wait_h"; 8 9 Event->signal(signal=>'CHLD', cb=>sub{ 10 my $kid; 11 do { 12 $kid = waitpid(-1, WNOHANG); 13 } while ($kid > 0); 14 }); 15 16 Event->timer(after=>1, interval=>2, cb=>sub { 17 print "$$: timer\n"; 18 my $pid = fork(); 19 return unless (defined($pid)); 20 return if ($pid); 21 22 print "child: $$\n"; 23 `sleep 5`; 24 exit(); # you can also call Event::unloop here. 25 26 }); 27 28 Event::loop(); 29 print "Unloop resumes code here\n";
In reply to Re: Event-based app and fork()
by reenen
in thread Event-based app and fork()
by powerman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |