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'll see stuff like components.registerAdapter. It's just magic t=
o<br>
create a FingerFactoryFromService, giving its constructor f, the<br>
"Finger Service". What happens here is that "f", 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', monospace">FingerService</font> inherits <font class=
=3D"Apple-style-span" face=3D"'courier new', monospace">service.Ser=
vice</font> and implements the <font class=3D"Apple-style-span" face=3D"=
9;courier new', monospace">startService</font> event, so it *is* a serv=
ice that can be run by the service framework; it just isn't one of the =
<font class=3D"Apple-style-span" face=3D"'courier new', monospace">=
twisted.application.internet</font> services, like <font class=3D"Apple-sty=
le-span" face=3D"'courier new', monospace">internet.TCPServer</font=
>.</div>
<div>Moreover, it needs to have <font class=3D"Apple-style-span" face=3D"&#=
39;courier new', monospace">startService</font> called, somehow... and =
what I'm saying is that in the full example (provided in<font class=3D"=
Apple-style-span" face=3D"'courier new', 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'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 "f", the Finger Service, "Finger Shar=
ed Data".<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 "f", the Finger Service, which has nothing to d=
o<br>
with twisted's mechanism. It'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've read it many times over the years ;) It&#=
39;s=C2=A0surprisingly complete as an example...you just don't know tha=
t in the beginning.</div>
<div><br></div><div>The topic area of this question is something I'm tr=
ying to squeeze out of this tutorial series; I'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"'co=
urier new', 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"'courier new', 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'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 <<a href=3D"mailto:deldot=
dr at gmail.com">deldotdr at gmail.com</a>> wrote:<br>
> Hello,<br>
> I am confused about how the FingerService gets started in the<br>
> finger/finger.py makeService function. It is never assigned a service =
parent<br>
> and it can't service getUser requests if its startService method i=
sn't<br>
> called; you get an AttributeError:=C2=A0"no attribute 'users&=
#39;" the way it works<br>
> now. Is this a bug?<br>
> The most sensible thing, in this case, seems to be setting the FingerS=
ervice<br>
> parent to be the MultiService container that all of the interent servi=
ces<br>
> are added to in the makeService function.=C2=A0Is that correct?<br>
> I'm wondering if their are any other=C2=A0strategies people use fo=
r starting<br>
> non-internet services.<br>
> For instance, if instead of reading a file to get to my user db, I mig=
ht<br>
> want to start a redis client and read from redis to service a getUser =
call.<br>
> But that means I'd want to make sure the startService=C2=A0call su=
cceeded (the<br>
> redis connection was made) before one of the internet services tries t=
o use<br>
> the FingerService (a timing problem that doesn't exist when just r=
eading a<br>
> file)...or something. Maybe I'm really just wondering how the twis=
ted<br>
> application framework handles exceptions that occur for startService c=
alls.<br>
> Maybe I need something else to handle that kind of thing?<br>
> I'm also wondering if it's ever a good idea to make a extensio=
n<br>
> of=C2=A0ServerFactory=C2=A0(that adapts a Service)=C2=A0that calls=C2=
=A0Service.startService<br>
> when Factory.startServer is called (and Service.stopService when<br>
> Factory.stopFactory is called)?<br>
> And I'm looking for more use cases/projects (beyond the finger tut=
orial)<br>
> that really showcase the twisted application framework. Any references=
would<br>
> be appreciated!<br>
> Thanks!<br>
> -Dorian<br>
</div></div>> _______________________________________________<br>
> Twisted-Python mailing list<br>
> <a href=3D"mailto:Twisted-Python at twistedmatrix.com">Twisted-Python at twi=
stedmatrix.com</a><br>
> <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>
><br>
><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