No subject


Wed Feb 23 11:29:31 MST 2011


<br>
h =3D internet.TCPServer(79, IFingerFactory(f))<br>
<br>
notice IFingerFactory? If you read the earlier parts of the tutorial,<br>
you&#39;ll see stuff like components.registerAdapter. It&#39;s just magic t=
o<br>
create a FingerFactoryFromService, giving its constructor f, the<br>
&quot;Finger Service&quot;. What happens here is that &quot;f&quot;, the Fi=
nger Service,<br>
is different from the service.Service within the Twisted Framework.<br></bl=
ockquote><div><br></div><div>The <font class=3D"Apple-style-span" face=3D"&=
#39;courier new&#39;, monospace">FingerService</font> inherits <font class=
=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">service.Ser=
vice</font> and implements the <font class=3D"Apple-style-span" face=3D"&#3=
9;courier new&#39;, monospace">startService</font> event, so it *is* a serv=
ice that can be run by the service framework; it just isn&#39;t one of the =
<font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=
twisted.application.internet</font> services, like <font class=3D"Apple-sty=
le-span" face=3D"&#39;courier new&#39;, monospace">internet.TCPServer</font=
>.</div>

<div>Moreover, it needs to have <font class=3D"Apple-style-span" face=3D"&#=
39;courier new&#39;, monospace">startService</font> called, somehow... and =
what I&#39;m saying is that in the full example (provided in<font class=3D"=
Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=C2=A0twisted/d=
oc/core/howto/tutorial/listings/finger/finger/finger.py</font>) it is not c=
alled, and if you actually try using it, it doesn&#39;t work.</div>

<div>=C2=A0</div><div><br></div><blockquote class=3D"gmail_quote" style=3D"=
margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
You might as well call &quot;f&quot;, the Finger Service, &quot;Finger Shar=
ed Data&quot;.<br>
<br>
What really happens here is<br>
<br>
h is the service that has parent s, MultiService. s is then returned<br>
and started by the application.<br>
<br>
h contains a factory that gets run.<br>
<br>
The factory knows &quot;f&quot;, the Finger Service, which has nothing to d=
o<br>
with twisted&#39;s mechanism. It&#39;s more of a demo for the component bas=
ed<br>
framework. f is a way to share data and methods and states across<br>
multiple factories.<br>
<br>
I am also very new to twisted, so I **hope** this understanding of<br>
mine is correct ...<br>
<br>
I strongly recommend you read through the entire tutorial. They build<br>
very incrementally, so most of the time the code is repeated so you<br>
can just skim through it if you had started from the beginning.<br></blockq=
uote><div><br></div><div>I&#39;ve read it many times over the years ;) It&#=
39;s=C2=A0surprisingly complete as an example...you just don&#39;t know tha=
t in the beginning.</div>

<div><br></div><div>The topic area of this question is something I&#39;m tr=
ying to squeeze out of this tutorial series; I&#39;m encountering conceptua=
l questions beyond the mechanics of how the framework works (which the tuto=
rial does a great job of explaining) like:=C2=A0</div>

<div>should I ever make a tree of=C2=A0dependent=C2=A0services?</div><div>W=
hat if I do something in a <font class=3D"Apple-style-span" face=3D"&#39;co=
urier new&#39;, monospace">startService</font> method that I want to make s=
ure works before other services get their <font class=3D"Apple-style-span" =
face=3D"&#39;courier new&#39;, monospace">startService</font> called?=C2=A0=
</div>

<div>If I create a bunch of business services (that just provide pure funct=
ionality) that I then adapt for deployment in different t.a.internet servic=
es, should I put the business services in their own MultiService and the in=
ternet services in their own MutiService container?=C2=A0</div>

<div><br></div><div>Like I said, more showcasing of use cases would help su=
ggest answers to these kind of questions. I see a lot of possibilities, but=
 haven&#39;t put in the time in the trenches to try them all out ;)</div>

<div><br></div><div>Thanks,</div><div>-Dorian</div><div>=C2=A0</div><div><b=
r></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border=
-left:1px #ccc solid;padding-left:1ex;">
<br>
David Kao<br>
<div><div></div><div class=3D"h5"><br>
<br>
<br>
On Fri, Sep 30, 2011 at 5:28 AM, Dorian Raymer &lt;<a href=3D"mailto:deldot=
dr at gmail.com">deldotdr at gmail.com</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt; I am confused about how the FingerService gets started in the<br>
&gt; finger/finger.py makeService function. It is never assigned a service =
parent<br>
&gt; and it can&#39;t service getUser requests if its startService method i=
sn&#39;t<br>
&gt; called; you get an AttributeError:=C2=A0&quot;no attribute &#39;users&=
#39;&quot; the way it works<br>
&gt; now. Is this a bug?<br>
&gt; The most sensible thing, in this case, seems to be setting the FingerS=
ervice<br>
&gt; parent to be the MultiService container that all of the interent servi=
ces<br>
&gt; are added to in the makeService function.=C2=A0Is that correct?<br>
&gt; I&#39;m wondering if their are any other=C2=A0strategies people use fo=
r starting<br>
&gt; non-internet services.<br>
&gt; For instance, if instead of reading a file to get to my user db, I mig=
ht<br>
&gt; want to start a redis client and read from redis to service a getUser =
call.<br>
&gt; But that means I&#39;d want to make sure the startService=C2=A0call su=
cceeded (the<br>
&gt; redis connection was made) before one of the internet services tries t=
o use<br>
&gt; the FingerService (a timing problem that doesn&#39;t exist when just r=
eading a<br>
&gt; file)...or something. Maybe I&#39;m really just wondering how the twis=
ted<br>
&gt; application framework handles exceptions that occur for startService c=
alls.<br>
&gt; Maybe I need something else to handle that kind of thing?<br>
&gt; I&#39;m also wondering if it&#39;s ever a good idea to make a extensio=
n<br>
&gt; of=C2=A0ServerFactory=C2=A0(that adapts a Service)=C2=A0that calls=C2=
=A0Service.startService<br>
&gt; when Factory.startServer is called (and Service.stopService when<br>
&gt; Factory.stopFactory is called)?<br>
&gt; And I&#39;m looking for more use cases/projects (beyond the finger tut=
orial)<br>
&gt; that really showcase the twisted application framework. Any references=
 would<br>
&gt; be appreciated!<br>
&gt; Thanks!<br>
&gt; -Dorian<br>
</div></div>&gt; _______________________________________________<br>
&gt; Twisted-Python mailing list<br>
&gt; <a href=3D"mailto:Twisted-Python at twistedmatrix.com">Twisted-Python at twi=
stedmatrix.com</a><br>
&gt; <a href=3D"http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-p=
ython" target=3D"_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/=
twisted-python</a><br>
&gt;<br>
&gt;<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href=3D"mailto:Twisted-Python at twistedmatrix.com">Twisted-Python at twistedm=
atrix.com</a><br>
<a href=3D"http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python=
" target=3D"_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twist=
ed-python</a><br>
</blockquote></div><br>

--0015174788367b000d04ae1bc660--



More information about the Twisted-Python mailing list