I am creating a script, that will SSH to several hosts, get stuff, parse it and return. Because I wait for server response, I'm using threading.  Real script is more complex, so I created this simple program to demonstrate logic. In real application 'timer' function does ssh with paramiko and parsing, 'main' is pretty much same. Do I need to use threading.Lock() in this program?from threading import Threadimport timeimport randomimport queue'''This function demonstrates usage of threads with queue'''que = queue.Queue()def timer(name, delay, que):  # timer's name, time.sleep() delay, queue.Queue() object    time.sleep(delay)  # sleep    que.put(name +  is done after  + str(delay) +  seconds)  # add items to queue, used when threaded    return name +  is done after  + str(delay) +  seconds  # this is used if fuction is called directlydef main(repeat):    threads = []  # stores threads after they are started. needed to join threads    out = []      # used for return    for i in range(1, repeat):  # Will loop few times, executing threads        t = Thread(target=timer, args=(('timer' + str(i)), random.choice([2, 3, 2]), que))        t.start()        threads.append(t)    for t in threads:        t.join()        # Join is needed so that main function waits for threads. We need this to return out list    while not que.empty():      # At this point threads are completed and joined. so we can dequeue que variable        out.append(que.get())    print(main completed)    return outstart_time = time.time()        # To measure timeif __name__ == '__main__':    print('\n'.join(main(30)),)print(--- Done in %s seconds --- % (time.time() - start_time))
Demonstration of processing a queue of no-op threads
python;python 3.x;multithreading;queue