[Twisted-Python] The Trial of the DirtyReactorError
Matthew Glubb
matt at zgroupplc.com
Fri Apr 13 01:19:45 MDT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Thanks for your advice, glyph. I'll probably end up calling listenTCP
from within the factory and shutting it down on call or errback.
Regards,
Matt
On 12 Apr 2007, at 19:56, glyph at divmod.com wrote:
> On 04:53 pm, matt at zgroupplc.com wrote:
>> 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.
>
> Putting the stopListening call into the middle of the actual test
> method would definitely be wrong.
>
> However, putting the listenTCP in the setUp and the stopListening
> in the tearDown would be entirely appropriate. If the code under
> test dynamically calls stopListening and might fail before then,
> then a tearDown by itself might be appropriate.
>> 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?
>
> This is, in part, a weakness of the IProtocolFactory interface.
> Calls to doStart and doStop should really receive an IListeningPort
> argument.
>
> However, this is a minor wart. listenTCP returns the Port, and
> hooking this up to your server factory in application code should
> be easy enough.
>> 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.
>
> If they are "always shut down", what event currently shuts them
> down? Have your test trigger that event. If they're one-shot, then
> perhaps the method that calls listenTCP should be on the factory
> itself, making it even easier to keep track of the Port instance it
> is associated with.
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
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>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
iD8DBQFGHy8UyI6MkdKPngkRAlH6AJ9bKzXeD2resG9USuAnWwCvoEaVEgCePCDy
rGROSFHTjmkQgBDHdDQ09o0=
=k9Gq
-----END PGP SIGNATURE-----
More information about the Twisted-Python
mailing list