[Twisted-Python] Plugin Example - review appreciated

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Fri Jun 24 12:23:36 EDT 2011


On 03:41 pm, robert.waters at gmail.com wrote:
>On Tue, Jun 21, 2011 at 5:32 PM, <exarkun at twistedmatrix.com> wrote:
>>
>>Don't define Options or makeService in the dropin file.

The system will perform better if there is less code in the dropin file 
(or imported by the dropin file).  There are some ideas to add an 
optimization which will make this irrelevant, but someone needs to 
implement them before they'll matter.
>>Use twisted.application.service.ServiceMaker instead of implementing
>>your own.

It's just less code to use `ServiceMaker`.  It should be flexible enough 
for any twistd plugin.  This interacts with the previous point as well, 
ServiceMaker avoids loading your Options and makeService implementation 
until someone actually invokes your twistd plugin.
>>  Don't use the global reactor in SetupService.

Using the global reactor makes code less easily testable.  This isn't 
specific to plugins, you should avoid the global reactor in all your 
Twisted-using code.  Accept it as a parameter instead.
>>
>Would you please elaborate on the three items above?
>Most of the plugin code that I've used as examples for my own have all
>violated at least two of those.

Hope that helps!

Jean-Paul



More information about the Twisted-Python mailing list