def worker():
    'Stop at 1; otherwise if odd then load 3*x+1; or if even then divide by two'
    name = threading.currentThread().getName()
    while True:
        x = q.get()
        sys.stdout.write('%s\t%d\n' % (name, x))
        if x <= 1:
            sys.stdout.write('!\n')
        elif x % 2 == 1:
            q.put(x * 3 + 1)
        else:
            q.put(x // 2)
        q.task_done()
Stop at 1; otherwise if odd then load 3*x+1; or if even then divide by two
recipes/Python/475160_TaskQueue/recipe-475160.py