[Twisted-Python] Writing Servers

A S abs621 at yahoo.com
Wed Mar 15 11:36:17 EST 2006


It is said all over the documentation

That when connection is accepted the new *instance* of
a protocol is created. However as it is single
threaded, can use the same instance?

For example (In case of UDP):

port = x;

#some proto subclass of AbstractDatagramProtocol
#this protocol does not does nt delegate request to
threads. I assume request is served quickly

proto = Proto() 

for if in ("eth0", "eth1")
    addr = getAddr(if)
    reactor.listenUDP(port, proto, interface = addr,)

I want to have same protocol *instance running* for
diff interface on same port. As this protocol does not
store any state.

Also instead of creating one when connection comes and
descard is when connection is broken. Use a single

however, internet/protocol.py does not allow it?

def makeConnection(self, transport):
        assert self.transport == None
        self.transport = transport

Can not i use the same instance of the protocol for
each connection instead of getting new instance every
time. As it is single threaded and it must return
before next connection in q is served?

I am once the datagramReceived is call, it must return
before any other request is served. (i am not using
any deferrer)

Q1) Am i missing some concept?

Q2) What if the request is delegated to deferrer or
threads, can we still use the same instance of
protocol class?

Q3) What are the ways to create deferrer itself
There is little about it, reactor callfromthread or
callinthread? Any good doc?


Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 

More information about the Twisted-Python mailing list