I’m sorry, I don’t understand why you want threading here.
I don’t fully understand your loop logic, but I think all you want is
to interleave two sequences A and B, like this:
A = [1, 2, 3, 4, 5, 6]
B = ['a', 'b', 'c', 'd', 'e', 'f']
# process 1, 'a', 2, 'b', 3, 'c', etc in that order.
Is that what you want? You don’t need threads for that. Threads will
just add a HUGE amount of complexity and non-determinism (you can’t
control the order that the threads run) and hurt performance a lot.
If you want something different, please explain in more detail what you
want, but here is how you can interleave two lists like A and B.
# stop on the shortest list
def interleave(a, b):
for x, y in zip(a, b):
yield x
yield y
# A shorter version of the above:
from itertools import chain
def interleave(a, b):
return chain.from_iterator(zip(a, b))
# Now process the items.
for item in interleave(alist, blist):
process(item)
If you want to pad the shorter list with a pad value, so that they are
the same length, change the call to “zip” to “zip_longest” like this:
from itertools import zip_longest
def interleave(a, b):
for x, y in zip_longest(a, b, fillvalue='padding'):
yield x
yield y