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.
Try this:
import twisted.application
application = twisted.application.service.Application("Scotty's UDP server")
twisted.application.internet.UDPServer(PORT, BaseThreadedUDPServer()).setServiceParent(application)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With