trying to run planet.py via mod_python
Duarte Carreira
dncarreira at gmail.com
Mon Nov 9 21:31:48 EST 2009
Seems code was a bit garbled, so trying again.
Duarte
#!/usr/bin/perl
use CGI qw(:standard);
use CGI::Carp 'fatalsToBrowser';
$|=1;
$CommandTimeoutDuration = 180;
print header;
print start_html('Run Planet');
print "<pre>";
$command = "/path_to/venus/planet.py /path_to/config.ini";
$command .= " 1>&1 2>&1";
$SIG{'ALRM'} = \&CommandTimeout;
alarm($CommandTimeoutDuration);
open IN, "$command |" or
die "Could not execute \"$command\": $!\n";
while(<IN>) {
$_ =~s/(\n|\r\n)$//;
print "$_\n";
} close IN;
print "</pre>";
print end_html;
#------------------------------------------------------------------------------
# This function is called when the timeout for a command expires. We need to
# terminate the script immediately. This function is valid only on Unix. It
is # never called when the script is running on NT.
#------------------------------------------------------------------------------
sub CommandTimeout {
alarm(0);
print <<END;
<code> Command exceeded maximum time of $CommandTimeoutDuration second(s).
<br>Killed it!
<code>
END
exit;
}
On Mon, Nov 9, 2009 at 1:00 AM, <devel-request at lists.planetplanet.org>wrote:
> ------------------------------
>
> Message: 2
> Date: Sun, 8 Nov 2009 22:30:27 +0000
> From: Duarte Carreira <dncarreira at gmail.com>
> Subject: Re: trying to run planet.py via mod_python
> To: devel at lists.planetplanet.org
> Message-ID:
> <6717b0ac0911081430w3ba6e25ds217d648c40776d0f at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> So I've been working on a script and came up with this by copy/pasting
> several examples found googling around.
> It works (to some extent). I tried to output each line from planet.py, but
> it only ouputs everything in the end. This results in a timeout error that
> I
> wanted to prevent. I also tried to kill the script if it takes too long but
> this hasn't been tested.
>
> I'm posting the script here if anyone is interested. If anyone can say why
> the ouput is not done line-by-line it would be great.
>
> Duarte
>
> #!/usr/bin/perl use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser';
> $|=1; $CommandTimeoutDuration = 180; print header; print start_html('Run
> Planet'); print "<pre>"; $command = "/path_to/venus/planet.py
> /path_to/config.ini"; $command .= " 1>&1 2>&1"; $SIG{'ALRM'} =
> \&CommandTimeout; alarm($CommandTimeoutDuration); open IN, "$command |" or
> die "Could not execute \"$command\": $!\n"; while(<IN>) { $_ =~
> s/(\n|\r\n)$//; print "$_\n"; } close IN; print "</pre>"; print end_html;
>
> #------------------------------------------------------------------------------
> # This function is called when the timeout for a command expires. We need
> to
> # terminate the script immediately. This function is valid only on Unix. It
> is # never called when the script is running on NT.
>
> #------------------------------------------------------------------------------
> sub CommandTimeout { alarm(0); print <<END; <code> Command exceeded maximum
> time of $CommandTimeoutDuration second(s). <br>Killed it! <code> END exit;
> }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /archives/devel/attachments/20091109/9c98d171/attachment.htm
More information about the devel
mailing list