Multithreading With Queue In Python 3

Snippet 1
  

import pandas as pd
import threading
import time
from multiprocessing import Queue
my_queue = Queue(maxsize=0)

#Let us define our worker

def worker(my_queue):

 #Add some time to fill up the queue
 time.sleep(5)
 while(my_queue.qsize() > 0):
      entry = my_queue.get()
 

#Let us define our threads here

num_threads = 10
threads = []
try:
  for i in range(num_threads):
      t = threading.Thread(target=worker,args=(my_queue)
      t.start()
      threads.append(t)
except:
 print ("Error: unable to start thread")
 

#This is our main starting code.

def main():
  df = pd.read_csv('nasdaq100.csv',encoding='UTF-8',delimiter="\t")
  for index, row in df.iterrows():
      my_queue.put(row)
      while(1):
          if my_queue.qsize() > 5:
              time.sleep(5)
          else:
              break
main()