Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Advice: Async Options for fire-and-forget subroutine

by mwb613 (Beadle)
on Oct 21, 2017 at 06:45 UTC ( [id://1201783]=note: print w/replies, xml ) Need Help??


in reply to Re: Advice: Async Options for fire-and-forget subroutine
in thread Advice: Async Options for fire-and-forget subroutine

Since I am stuck with 5.16 I tried another module, Async. It seems to work ok but there's one bit of behavior that I didn't expect (though I probably should have): if the parent script finishes, the subroutine fired by Async finishes as well (I was testing some writes after a sleep command). I guess this makes sense since the process is dying and thus everything on it's stack gets popped but I didn't comprehend this when I first started thinking about the problem.

I haven't yet tested it within the OpenSIPs module and don't know enough about how it works to wager a guess as to whether it keeps a persistent Perl env going while it operates (I know it spawns individual worker processes so each of them might have a unique env as well). Is it an unreasonable expectation to keep looking for a module that might be able to "fire-and-forget" a subroutine that can keep running even if the parent process dies?

Replies are listed 'Best First'.
Re^3: Advice: Async Options for fire-and-forget subroutine
by RonW (Parson) on Oct 24, 2017 at 21:02 UTC

    In most cases, a parent process (or thread) should wait for its children to finish. In the case of processes, this (usually) cleans up zombies. In the case of threads, you have to wait until the threads are finished (or some reasonable time out) before ending the main, as this will also end the process containing all the threads.

    It is possible for child processes to "detach" from their parent. I'm pretty sure that most of the fork manager type modules in CPAN will have an option for this.

    Paraphrasing a fictitious soldier, "Fire-and-forget is fine as long as you never forget."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201783]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (8)
As of 2024-03-28 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found