laziness, impatience, and hubris | |
PerlMonks |
Re: Forking two processes in parallelby Tanktalus (Canon) |
on Mar 06, 2016 at 02:25 UTC ( [id://1156903]=note: print w/replies, xml ) | Need Help?? |
Your fork_bot doesn't return until it has slept. You need to fork both off, and manage the sleep events in the parent. And the parent has to wait around for the children to finish, else the parent exiting may also terminate its children. Personally, I've found that using an event manager simplifies this greatly. Completely untested code: Now, I'm sure you can do this equally as well with other event handlers, or with threads. This is just what I'm used to. Coro can simplify this a bit further, but at this point it's not enough to warrant, IMO. (It would invert the timeout into a Coro-version of sleep, but I don't think that's a huge benefit here.) Also, we can use this to also clean up the $w watcher, to eliminate that timer if the child exits before the timer runs out. Hope that helps.
In Section
Seekers of Perl Wisdom
|
|