[Twisted-Python] leakage between tests with trial when code under test uses deferToThread

Glyph glyph at twistedmatrix.com
Fri Nov 23 15:22:54 MST 2018



> On Nov 23, 2018, at 7:58 AM, Chris Withers <chris at withers.org> wrote:
> 
> Hi All,
> 
> Does trial do anything to clean up stuff that's been passed to deferToThread?

Nope.  It does its best to clean up stuff that it knows is "in" the reactor (sockets, timers, and the like), but since threads can kind of do ~whatever~ there hasn't been support for that.

deferToThread is a bit of a special case and you make a good point here: there should probably be special support for it in trial.

> I'm seeing what looks like leakage between tests where stuff that is deferred to a thread from a LoopingCall is resulting in a DelayedCall ending up in the reactor for the next test.
> Does that ring any bells?

That can definitely happen.  For the time being you probably want to add your own deferToThread layer and have a testCase.addCleanup that makes sure all the relevant Deferreds have fired.

-g



More information about the Twisted-Python mailing list