title: Issues with Python Threading and Code in general
body: <p>Given the following Python3 code, with threading:</p>
  
  <pre><code>class main:
      def __init__(self):
          self.text = open(os.getcwd()+"/FileScanLogs.txt", "a+")
          self.hashlist = queue.Queue()
          self.filelist = queue.Queue()
          self.top = '/home/'
          for y in range(12):
              self.u = threading.Thread(target=self.md5hash)
              self.u.daemon = True
              self.u.start()
          for x in range(4):
              self.t = threading.Thread(target=self.threader)
              self.t.daemon = True
              self.t.start()
          main.body(self)
  
      def body(self):
          start = time.time()
          self.text.write("Time now is " + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + "\n")
          for root, dirs, files in os.walk(self.top):
              for f in files:
                  path = os.path.join(root,f)
                  self.filelist.put(path)
          self.t.join()
          self.u.join()
          self.text.write("Total time taken     : " + str(time.time() - start) + "\n")
          print("Log file is created as " + os.getcwd() + "/FileScanLogs.txt")
  
      def md5hash(self):
          while True:
              entry = self.filelist.get()
              //hashing//
              lists = finalhash + ',' + entry
              self.hashlist.put(lists)
              self.filelist.task_done()
  
      def compare(self, hashed, path):
          f = open(os.getcwd() + "/database.csv", 'r')
          for row in f:
              if row.split(':')[1] == hashed:
                  print("Suspicious File!")
                  print("Suspecfs: " + row.split(':')[2] + "File name : " + path)
  
      def threader(self):
          while True:
              item = self.hashlist.get()
              hashes = item.split(',')[0]
              path = item.split(',')[1]
              self.compare(hashes, path)
              self.hashlist.task_done()
  
  main()
  </code></pre>
  
  <p>Problem 1: In <code>def body(self)</code>, there exist the line <code>self.text.write("Time now is ...")</code>. This line does not appear in the Log File that is created.</p>
  
  <p>Problem 2: In <code>def compare(self, hashed, path)</code>, there exist a line that prints "Suspicious File!" and the <code>file path</code> every time there is a hash collision. This line always prints out of order as the 4 threads <code>t</code> are fighting over who will print first. For this, I think I need to know how to let Python threads run <code>print</code> commands sequentially instead of however they like -- how?</p>
  
  <p>Problem 3: In <code>def body(self)</code>, there exist lines <code>self.u.join()</code> and <code>self.t.join()</code>. The command <code>join()</code>, according to the best of my knowledge, is a command waiting for the thread to terminate before continuing. The threads are both not terminating.</p>
  
  <p>Additional information 1: I am writing multi-threading as I need the code to be converted to multi-processing later.</p>
  
  <p>Additional information 2: Please do let me know if I have misunderstood any commands/syntax in my code as you are skimming through.</p>