Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twisted UDP Server - daemonize?

I have the following UDP server using Twisted:

# init the thread capability
threadable.init(1)

# set the thread pool size
reactor.suggestThreadPoolSize(32)

class BaseThreadedUDPServer(DatagramProtocol):
    def datagramReceived(self, datagram, (host, port)):
        #do some stuff here...

def main():
    reactor.listenUDP(PORT, BaseThreadedUDPServer())
    reactor.run()

if __name__ == '__main__':
    main()

I would like to be able to daemonize this, so from what I have read I should be doing something with a .tac file that I can start with "twistd -y my_udp_server_file.tac" - the problem is I can't find any documentation on how to do this with this kind of setup. All I can find is examples on how to daemonize simple TCP echo servers (with a .tac file, that is) - I need a multi-threaded UDP server like the one I have.

Any direction would be greatly appreciated.

like image 656
Scott Avatar asked Dec 06 '25 07:12

Scott


1 Answers

Try this:

import twisted.application
application = twisted.application.service.Application("Scotty's UDP server")
twisted.application.internet.UDPServer(PORT, BaseThreadedUDPServer()).setServiceParent(application)
like image 105
Robie Basak Avatar answered Dec 07 '25 20:12

Robie Basak