2011-06-24

Twisted Python Plugin Example

At EuroPython 2011 there was some very successful and popular training given on Twisted, presented
by Orestis Markou. The room was so packed the first time he gave the training on the Monday of the
conference, he was asked to do it a second time on the Wednesday.

Orestis asked me to put together a few things about best practice for deploying Twisted code. I have deployed many twisted servers so I was more than happy to oblige.

I put on bitbucket my twisted-plugin-example that I quickly composed for an example.

It shows the following:

  • The nice way to write a twisted/plugin/foo.py file.
  • How to use twistd to start your server instead of using a script containing reactor.run()
  • serverFromString + StreamServerEndpointService (i.e. string endpoint descriptions) to specify where to listen.
  • twisted.python.usage.Options
  • How to write a simple custom Service to do any additional setup required.


I think it's an acceptable starting point if someone has a Protocol/Factory and wants to start the transition from "I've experimented with this and it works" to "This is a body of code I would feel okay packaging with distutils and deploying in a VirtualEnv on a hundred servers"

If you have any comments, patches are accepted of course. :)

No comments: