[Twisted-Python] Bug in Finger Tutorial?

David Kao a.libran at gmail.com
Thu Sep 29 15:44:51 MDT 2011


I'll take care of the first question.

>From The Evolution of Finger: making a finger library,

h = internet.TCPServer(79, IFingerFactory(f))

notice IFingerFactory? If you read the earlier parts of the tutorial,
you'll see stuff like components.registerAdapter. It's just magic to
create a FingerFactoryFromService, giving its constructor f, the
"Finger Service". What happens here is that "f", the Finger Service,
is different from the service.Service within the Twisted Framework.
You might as well call "f", the Finger Service, "Finger Shared Data".

What really happens here is

h is the service that has parent s, MultiService. s is then returned
and started by the application.

h contains a factory that gets run.

The factory knows "f", the Finger Service, which has nothing to do
with twisted's mechanism. It's more of a demo for the component based
framework. f is a way to share data and methods and states across
multiple factories.

I am also very new to twisted, so I **hope** this understanding of
mine is correct ...

I strongly recommend you read through the entire tutorial. They build
very incrementally, so most of the time the code is repeated so you
can just skim through it if you had started from the beginning.

David Kao



On Fri, Sep 30, 2011 at 5:28 AM, Dorian Raymer <deldotdr at gmail.com> wrote:
> Hello,
> I am confused about how the FingerService gets started in the
> finger/finger.py makeService function. It is never assigned a service parent
> and it can't service getUser requests if its startService method isn't
> called; you get an AttributeError: "no attribute 'users'" the way it works
> now. Is this a bug?
> The most sensible thing, in this case, seems to be setting the FingerService
> parent to be the MultiService container that all of the interent services
> are added to in the makeService function. Is that correct?
> I'm wondering if their are any other strategies people use for starting
> non-internet services.
> For instance, if instead of reading a file to get to my user db, I might
> want to start a redis client and read from redis to service a getUser call.
> But that means I'd want to make sure the startService call succeeded (the
> redis connection was made) before one of the internet services tries to use
> the FingerService (a timing problem that doesn't exist when just reading a
> file)...or something. Maybe I'm really just wondering how the twisted
> application framework handles exceptions that occur for startService calls.
> Maybe I need something else to handle that kind of thing?
> I'm also wondering if it's ever a good idea to make a extension
> of ServerFactory (that adapts a Service) that calls Service.startService
> when Factory.startServer is called (and Service.stopService when
> Factory.stopFactory is called)?
> And I'm looking for more use cases/projects (beyond the finger tutorial)
> that really showcase the twisted application framework. Any references would
> be appreciated!
> Thanks!
> -Dorian
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>




More information about the Twisted-Python mailing list