Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 30151 invoked from network); 13 Dec 2007 10:00:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Dec 2007 10:00:04 -0000 Received: (qmail 90580 invoked by uid 500); 13 Dec 2007 09:59:48 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 89956 invoked by uid 500); 13 Dec 2007 09:59:47 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 89943 invoked by uid 99); 13 Dec 2007 09:59:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Dec 2007 01:59:47 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of torsten.foertsch@gmx.net designates 213.165.64.20 as permitted sender) Received: from [213.165.64.20] (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 13 Dec 2007 09:59:25 +0000 Received: (qmail invoked by alias); 13 Dec 2007 09:59:26 -0000 Received: from p57A5C6B8.dip.t-dialin.net (EHLO opi.home) [87.165.198.184] by mail.gmx.net (mp007) with SMTP; 13 Dec 2007 10:59:26 +0100 X-Authenticated: #1700068 X-Provags-ID: V01U2FsdGVkX1/1h0do9XL1k8OPp2x+y4pE/ETsvGi+Iw1hhB5gOB cu4FFxmTqa7ETl From: Torsten Foertsch To: modperl@perl.apache.org Subject: Re: register_cleanup Date: Thu, 13 Dec 2007 10:59:19 +0100 User-Agent: KMail/1.9.6 (enterprise 20070904.708012) Cc: Rolf Schaufelberger References: <200712122005.13257.rs@plusw.de> In-Reply-To: <200712122005.13257.rs@plusw.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200712131059.19936.torsten.foertsch@gmx.net> X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked by ClamAV on apache.org On Wed 12 Dec 2007, Rolf Schaufelberger wrote: > I'm on the way moving my app from mod_perl1 to mod_perl2. > The app is build with HTML::Mason an MasonX::WebApp. > Now I have a problem when trying to install a cleanup_handler. > My expectations are, that the funtcion I call returns to the browser and > move some long time computing to a cleanup_handler. > The code I use (sample): > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > use APR::Pool (); > =A0 > sub cleanup { > =A0 my $arg =3D shift; > =A0 for (1 .. $arg->{cnt} ) { > =A0 =A0 print STDERR "$_ =3D ", $arg->{name}, "\n"; > =A0 =A0 sleep(1); > =A0 } > } > =A0 > sub T_cleanup { > =A0 my $self=3D shift; > =A0 > =A0# either > =A0 my $r =3D $self->{__apache_req__}; > =A0 $r->pool->cleanup_register (\&cleanup, {name=3D> 'test', cnt=3D>10}); This should work, see below. > # nor this works > # =A0 my $p =3D APR::Pool->new(); =A0 > # =A0$p->cleanup_register (\&cleanup, {name=3D> 'test', cnt=3D>10}); and it should not. $p is destroyed at the end of the subroutine. Hence the= =20 cleanup is run at that time, that means before Perl returns to mod_perl. > =A0 $self->redirect(path=3D>'/index.html'); > } > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > So when I call my method T_cleanup, the redirect is done AFTER cleanup has > counted down , i.e. after 10 seconds. I would expect that it returns at > once, an cleanup starts working AFTER the redirect. > The docs says, it would start the executen "after the pool goes out of > scope", which should be after the request object gets detroyed. Right ? > > So what am I doing wrong ? This one works for me: package My::Test; use strict; use Apache2::RequestRec (); use APR::Pool (); use Apache2::Const qw/-compile OK REDIRECT/; sub cleanup {=20 my $arg =3D shift;=20 for (1 .. $arg->{cnt} ) {=20 print STDERR "$_ =3D ", $arg->{name}, "\n";=20 sleep(1);=20 }=20 } sub handler { my $r=3D$_[0]; $r->pool->cleanup_register(\&cleanup, {name=3D> 'test', cnt=3D>10}); $r->headers_out->{Location}=3D'http://blah.blah/'; return Apache2::Const::REDIRECT; } SetHandler modperl PerlResponseHandler My::Test Torsten =2D- A: It reverses the normal flow of conversation. Q: What's wrong with top-posting? A: Top-posting. Q: What's the biggest scourge on plain text email discussions?