[Zope] external cgi

Passin, Tom tpassin@mitretek.org
Tue, 8 Oct 2002 11:16:53 -0400


This is a multi-part message in MIME format.

------_=_NextPart_001_01C26EDD.BBB8A441
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

 Liz Pelletier=20
[[
 Hi all - I am selecting certain records from a table. Within the
<dtml-in> loop, I need to execute a cgi script residing on a second
server (which is not hosting zope) for each row of returned data. How??
I can't use RESPONSE.redirect, that I know of, because it does not
return control to the originating zope page it was called from after
executing. I've installed ZCGI, but that doesn't seem to facilitate cgi
scripts on a different machine. I've tried a simple python script which
imports urllib and then try's a urlopen, but that didn't work either.
Has anybody had to solve a similar problem or know where I'm going wrong
?
]]
=20
I like external Python methods for that kind  of thing.  There are a few
things to beware of, though (not specific to external methods).  First,
the call for each row will have to complete before the next one starts,
which will probably be very time consuming.  To avoid this, you would
use multiple threads in an external method.  But even then, if one of
the sites does not respond for any reason, its thread will not return
(or it may have to wait for a long timeout, like minutes in some cases).
You will not be able to complete until all threads return, so you can
still get long delays.  To avoid this, it would be possible to write
code to test a site first to see if it responds, (you may have to get a
special socket library that can be interrupted if it is hanging - I know
that at least one such library exists for Python) but of course it would
be more complicated.
=20
To sum up, you can make this work with external methods but you should
see if you can come up with some way to avoid the need for going to a
site for each row.  Can you cache the data, for example?
=20
Cheers,
=20
Tom P

------_=_NextPart_001_01C26EDD.BBB8A441
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns=3D"http://www.w3.org/TR/REC-html40" xmlns:o =3D=20
"urn:schemas-microsoft-com:office:office" xmlns:w =3D=20
"urn:schemas-microsoft-com:office:word"><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<TITLE>Message</TITLE>

<META content=3DWord.Document name=3DProgId>
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<META content=3D"Microsoft Word 10" name=3DOriginator><LINK=20
href=3D"cid:filelist.xml@01C26E68.43D08B70" rel=3DFile-List><!--[if gte =
mso 9]><xml>
 <o:OfficeDocumentSettings>
  <o:DoNotRelyOnCSS/>
 </o:OfficeDocumentSettings>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DocumentKind>DocumentEmail</w:DocumentKind>
  <w:EnvelopeVis/>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]-->
<STYLE>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0in;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;
	text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;
	text-underline:single;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	mso-style-noshow:yes;
	mso-ansi-font-size:10.0pt;
	mso-bidi-font-size:10.0pt;
	font-family:Arial;
	mso-ascii-font-family:Arial;
	mso-hansi-font-family:Arial;
	mso-bidi-font-family:Arial;
	color:windowtext;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;
	mso-header-margin:.5in;
	mso-footer-margin:.5in;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
-->
</STYLE>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */=20
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin:0in;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";}
</style>
<![endif]--></HEAD>
<BODY lang=3DEN-US style=3D"tab-interval: .5in" vLink=3Dpurple =
link=3Dblue>
<DIV><FONT face=3DTahoma size=3D2>&nbsp;Liz Pelletier<SPAN=20
class=3D687455914-08102002><FONT face=3D"Palatino Linotype" =
color=3D#0000ff=20
size=3D3>&nbsp;</FONT></SPAN></FONT></DIV>
<DIV><FONT face=3DTahoma size=3D2><SPAN=20
class=3D687455914-08102002>[[</SPAN></FONT></DIV>
<DIV><FONT face=3DTahoma size=3D2><SPAN=20
class=3D687455914-08102002>&nbsp;</SPAN></FONT><FONT face=3DArial =
size=3D2><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">Hi all - I am selecting =
certain=20
records from a table. Within the &lt;<SPAN =
class=3DSpellE>dtml</SPAN>-in&gt; loop,=20
I need to execute a <SPAN class=3DSpellE>cgi</SPAN> script residing on a =
second=20
server (which is not hosting zope) for each row of returned data. How?? =
I can&#8217;t=20
use <SPAN class=3DSpellE><SPAN =
class=3DGramE>RESPONSE.redirect</SPAN></SPAN><SPAN=20
class=3DGramE>, that</SPAN> I know of, because it does not return =
control to the=20
originating zope page it was called from after executing. I&#8217;ve =
installed ZCGI,=20
but that doesn&#8217;t seem to facilitate <SPAN =
class=3DSpellE>cgi</SPAN> scripts on a=20
different machine. I&#8217;ve tried a simple python script which imports =
<SPAN=20
class=3DSpellE>urllib</SPAN> and then try&#8217;s <SPAN =
class=3DGramE>a</SPAN> <SPAN=20
class=3DSpellE>urlopen</SPAN>, but that didn&#8217;t work either. Has =
anybody had to=20
solve a similar problem or know where I&#8217;m going wrong<SPAN=20
class=3D687455914-08102002><FONT face=3D"Palatino Linotype" =
color=3D#0000ff=20
size=3D3>&nbsp;?</FONT></SPAN></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN =
class=3D687455914-08102002><FONT=20
face=3D"Palatino Linotype" color=3D#0000ff=20
size=3D3>]]</FONT></SPAN></SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN=20
class=3D687455914-08102002></SPAN></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN =
class=3D687455914-08102002><FONT=20
face=3D"Palatino Linotype" color=3D#0000ff size=3D3>I like =
external&nbsp;Python=20
methods&nbsp;for that kind </FONT>&nbsp;<FONT face=3D"Palatino Linotype" =

color=3D#0000ff size=3D3>of thing.&nbsp; There are a few things to =
beware of, though=20
(not specific to external methods).&nbsp; First, the call for each row =
will have=20
to complete before the next one starts, which will probably be very time =

consuming.&nbsp; To avoid this, you would use multiple threads in an =
external=20
method.&nbsp; But even then, if one of the sites does not respond for =
any=20
reason, its thread will not return (or it may have to wait for a long =
timeout,=20
like minutes in some cases).&nbsp; You will not be able to complete =
until all=20
threads return, so you can still get long delays.&nbsp; To avoid this, =
it would=20
be possible to write code to test a site first to see if it responds, =
(you may=20
have to get a special socket library that can be interrupted if it is =
hanging -=20
I know that at least one such library exists for Python) but of course =
it would=20
be more complicated.</FONT></SPAN></SPAN></FONT></DIV>
<DIV><FONT face=3D"Palatino Linotype" color=3D#0000ff size=3D3><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN=20
class=3D687455914-08102002></SPAN></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Palatino Linotype" color=3D#0000ff size=3D3><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN =
class=3D687455914-08102002>To=20
sum up, you can make this work with external methods but you should see =
if you=20
can come up with some way to avoid the need for going to a site for each =

row.&nbsp; Can you cache the data, for =
example?</SPAN></SPAN></FONT></DIV>
<DIV><FONT face=3D"Palatino Linotype" color=3D#0000ff size=3D3><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN=20
class=3D687455914-08102002></SPAN></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Palatino Linotype" color=3D#0000ff size=3D3><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN=20
class=3D687455914-08102002>Cheers,</SPAN></SPAN></FONT></DIV>
<DIV><FONT face=3D"Palatino Linotype" color=3D#0000ff size=3D3><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN=20
class=3D687455914-08102002></SPAN></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Palatino Linotype" color=3D#0000ff size=3D3><SPAN=20
style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"><SPAN =
class=3D687455914-08102002>Tom=20
P</SPAN></SPAN></FONT></DIV></BODY></HTML>

------_=_NextPart_001_01C26EDD.BBB8A441--