[Twisted-Python] Multithreaded UDP server in Twisted?

John Doe carlo.riva at gmail.com
Thu Aug 21 09:47:49 EDT 2008


Hi everyone,

I am trying to implement a multithreaded UDP server in Twisted:

from twisted.internet.protocol import DatagramProtocol
from twisted.internet import threads, reactor
from twisted.python import threadable
threadable.init(1)

reactor.suggestThreadPoolSize(32)

class EchoUDP(DatagramProtocol):

   def echoDatagram (self, datagram):
       print datagram

   def datagramReceived(self, datagram, address):
       self.transport.write(datagram, address)
       reactor.callInThread(self.echoDatagram(datagram))

def main():
   reactor.listenUDP(8000, EchoUDP())
   reactor.run()

if __name__ == '__main__':
   main()
although it is working it gives me following error:

Traceback (most recent call last):
 File "C:\Python25\lib\threading.py", line 460, in __bootstrap
   self.run()
 File "C:\Python25\lib\threading.py", line 440, in run
   self.__target(*self.__args, **self.__kwargs)
--- <exception caught here> ---
 File "C:\Python25\lib\site-packages\twisted\python\threadpool.py",
line 148, in _worker
   context.call(ctx, function, *args, **kwargs)
 File "C:\Python25\lib\site-packages\twisted\python\context.py", line
59, in callWithContext
   return self.currentContext().callWithContext(ctx, func, *args, **kw)
 File "C:\Python25\lib\site-packages\twisted\python\context.py", line
37, in callWithContext
   return func(*args,**kw)
exceptions.TypeError: 'NoneType' object is not callable

Does anybody know what is wrong?

Any help is *greatly* appreciated! ;)

Thanks in advance!

Cheers
Carlo




More information about the Twisted-Python mailing list