<div dir="ltr">Hi Russell,<br><br><br>The way to do this is to pass the reactor as a parameter, and use a Clock instead of the regular parameter for unit testing purposes. See also: <a href="https://twistedmatrix.com/documents/current/core/howto/trial.html">https://twistedmatrix.com/documents/current/core/howto/trial.html</a> ; that has a complete example of how to write unit tests that use Clock.<br>

<br>That way your unit tests will be fast, deterministic, and also very clean :-)<br><br><br>hth<br>lvh<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Mar 13, 2014 at 10:09 PM, Russell E. Owen <span dir="ltr"><<a href="mailto:rowen@uw.edu" target="_blank">rowen@uw.edu</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Is there a simple way to cancel all Twisted timers (pending<br>
reactor.callLater calls)?<br>
<br>
The reason I want to do this is to clean up a unit test without getting<br>
"dirty reactor" complaints.<br>
<br>
The system is a server that will rarely be shut down and does not have<br>
to shut down gracefully (i.e. I don't care if the reactor is dirty). But<br>
I want the unit tests to run cleanly, so for now I've been keeping a<br>
reference to each timer that I start, so my test cleanup code can<br>
manually cancel it. It's a lot of fuss, and makes timers harder to use<br>
than they should be. I admit that in many cases I need a reference to<br>
the timer anyway, since I may have to cancel it for reasons that matter<br>
to the server. But I hate having to do it for *every* timer. If there<br>
was a simple way to tell the reactor to cancel any outstanding<br>
"callLater" calls, the code would be much cleaner.<br>
<br>
<br>
-- Russell<br>
<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br></div>