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

Chris Withers chris at withers.org
Mon Nov 26 01:35:12 MST 2018


Forgot to include the list in my reply...

On 23/11/2018 22:27, Chris Withers wrote:
> On 23/11/2018 22:22, Glyph wrote:
>>
>>
>>> 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.
>
> Actually, looks like there's stuff in trial's Janitor class, but it 
> only kicks in after the suite is finished, and I'm seeing leakage 
> between tests within a suite...
>
>> 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.
>
> ...which I plan to add in carly in the meantime: basically block with 
> a timeout on everything in the threadpool finishing it's work.
>
> Speaking of which, I'm happy with how carly is turning out, but would 
> still welcome feedback, particularly on how the tests suites feel:
>
> https://github.com/cjw296/carly/tree/master/tests
>
> Just don't read hook.py unless you like head-bendy code ;-)

Okay, so here's what I came up with 
<https://github.com/cjw296/carly/commit/71a1d2bfd501f5c561712c75253fc23c28c3bba7#diff-3670fb1f3b913f6c1ec584fa64302c2dR17>. 
I'm not a fan of the sleep / busy loop pattern, but twisted makes it 
prettymuch impossible to get hold of the ThreadWorkers queue, so that I 
could block on them in this method. Any ideas on improvements would be 
very welcome!

cheers,

Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20181126/d4d3681b/attachment-0002.html>


More information about the Twisted-Python mailing list