trying to run planet.py via mod_python

Duarte Carreira dncarreira at gmail.com
Mon Nov 9 09:30:27 EST 2009


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; }

On Sun, Nov 8, 2009 at 10:24 PM, Duarte Carreira <dncarreira at gmail.com>wrote:

>
>
> ---------- Forwarded message ----------
> From: Duarte Carreira <dncarreira at gmail.com>
> Date: Fri, Nov 6, 2009 at 1:02 PM
> Subject: Re: trying to run planet.py via mod_python
> To: Alex Schröder <kensanata at gmail.com>
>
>
> Alex, sorry about that. Don't know how but I managed to send my previous
> email before I got to see your reply... gmail must have fooled me ;)
>
> I'm definitely going to try your script and post here the results But I'm
> very optimistic!
>
> Thanks,
> Duarte
>
>
>
> On Fri, Nov 6, 2009 at 11:04 AM, Alex Schröder <kensanata at gmail.com>wrote:
>
>> On Fri, Nov 6, 2009 at 11:54, Duarte Carreira <dncarreira at gmail.com>wrote:
>>
>>> I have mod_python working but cannot find a way to run planet.py... no
>>> output or error is shown on the webpage...
>>> If someone can send me an example script I'd appreciate it.
>>>
>>
>> Hm, didn't I just send you an example script that worked for me? Note how
>> my test.pl Perl script calls python.py. I don't think you need mod_python
>> for this. I just use the Perl script to handle the CGI parts because it's
>> what I'm most familiar with.
>>
>> Anyway, I actually installed and tested the setup I sent you, so I know it
>> works. If it still fails, you need to start looking for error logs and the
>> like.
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /archives/devel/attachments/20091108/ba2f454f/attachment.htm 


More information about the devel mailing list