<div dir="ltr">Any chance one of you would like to write a short article about it for the Advent Calendar of 2016? :)</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 8, 2015 at 8:15 AM, Andrew Beverley <span dir="ltr"><<a href="mailto:andy@andybev.com" target="_blank">andy@andybev.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 2015-07-08 00:58, Johandry Amador Segui wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Andy,<br>
<br>
I tried to use threads and it did not worked for me (maybe because of<br>
non safe thread modules I am using) so I use fork in a production<br>
application and it works good. I have some issues some times with<br>
MySQL that I have not fixed yet but they do not happen very often.<br>
<br>
This is an example of how I use it:<br>
<br>
sub execute {<br>
<br>
        # These 2 lines below were to eliminate the error that I mentioned<br>
before. It did not eliminated them just reduce them<br>
        my $dbh = database();<br>
        $dbh->{InactiveDestroy} = 1;<br>
<br>
        my $pid = fork();<br>
<br>
        if ($pid) {<br>
                # This is the parent (Dancer) in case you want to do something here<br>
                debug “Process started with PID $pid\n”;<br>
<br>
        } elsif ($pid == 0) {<br>
                # This is the child, here is where I do all I need<br>
                $template = ...<br>
        } else {<br>
                debug “Could not fork: $!\n”;<br>
        }<br>
<br>
        # I have a variable to know if I’m running this sub from the web or from CLI<br>
        if ($cli) {<br>
                my $output = waitpid($pid, 0);<br>
                print “The process finish with output: $output”;<br>
        }<br>
<br>
        return $template;<br>
}<br>
<br>
This is just an example, not the entire code. If someone has a<br>
suggestion or improvement, it is welcome.<br>
</blockquote>
<br></div></div>
Surely you need an exit() in there somewhere for the child process, otherwise you'll end up with lots of web server threads?<div class="HOEnZb"><div class="h5"><br>
<br>
Andy<br>
<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div></div></blockquote></div><br></div>