[Twisted-Python] The Trial of the DirtyReactorError

Matthew Glubb matt at zgroupplc.com
Thu Apr 12 12:53:25 EDT 2007

Hash: SHA1

Hi All,

I have to say that I am largely getting along famously with Twisted  
(and Python) now.

I have started writing unit tests for my application and when I run  
them using trial I sometimes get DirtyReactorErrors ('reactor left in  
unclean state'). This is a nice error. It tells me that I am not  
shutting down resources correctly which would otherwise be left  
hanging around and be difficult to debug.

I understand why this is occurring, its a simple matter of calling  
tcp.Port.stopListening() to suppress the error. However, I am more  
concerned with learning about where the most appropriate place to run  
this routine would be. I am not happy about running it in the unit  
test as it doesn't solve the problem, it just suppresses it. I can't  
seem to find an easy way to stop a port from listening from within a  
ServerFactory. Should I be writing a class that wraps the  
ServerFactory to run tcp.Port.stopListening() at the appropriate time?

Please bear in mind that I am creating multiple 'one-shot' servers  
that are always shut down as soon as they have done their business. I  
am guessing that the stopService methods would be more appropriate  
for a conventional server that serves multiple clients / requests.

Your thoughts?

Thanks a lot for your time :)


m a t t h e w   g l u b b

Z Group PLC

Tel: +44 (0) 8700 111 173
Fax: +44 (0) 8707 051 393
Txt: +44 (0) 7800 140 877
Web: <http://www.zgroupplc.com/>

This  email  and  any  files  transmitted  with it are  confidential and
intended solely for the use of the individual or entity to whom they are
addressed.  The opinions  expressed in this mail are those of the author
and do not necessarily  represent the views of the company.  If you have
received this email in error please notify <service at zgroupplc.com>

Version: GnuPG v1.4.1 (Darwin)


More information about the Twisted-Python mailing list