I wrote about a nice threading pattern using Queues for
synchronization a while ago. In
the meantime, I’ve stumbled across Trio
and I loved their concept of nurseries, which is basically a wrapper
around the threads-and-queues concept that also makes sure that threads
are properly joined and do not run out of control.
So today I ran across a case where I’d have to query large chunks of
data from two systems in parallel, that I would then have to compare and
merge into a third data set. Thus I needed a way to start two threads,
return stuff from them to the main thread, and join them back together.
A nursery came to mind, because it does just that. So that’s what I
used, and here’s the code for it!
Read more…