title: How to readfile / read in python, PyQt?
body: <p>I have the following code in PyQT, it is doing its job properly. There is a readfile function in a QThread. I want to start a &quot;loading&quot; animation when it is starting to find the hostnames in the file. And I want to stop the &quot;animation&quot; when it went through of all of it. Hostnames comes by user input and they append in a queue ( the queue can contain multiple hostnames). What it is doing now opening and closing the file constantly and like by that the loading animation is poping up and closing rapdily. Sure there is a way to open the file once and cycle through all the hostnames instead to open it for every hostname in the queue.</p>
  <p><strong>Here is the code:</strong></p>
  <pre class="lang-py prettyprint-override"><code>class Worker2(QThread):
     found = Signal(str)
     notFound = Signal(str)
     animation = Signal()
  
     def __init__(self):
         QThread.__init__(self)
         self.queue = Queue()
         
     
     def run(self):
         self.keepRunning = True
         while self.keepRunning:
  
             hostlist = self.queue.get()
             if not self.keepRunning:
                 break
             for hostname in hostlist.splitlines():
                 if not self.keepRunning:
                     break
                 if hostlist is None:
                     continue
                 self.animation.emit()
                 f = open(&quot;allhosts.txt&quot;, &quot;r&quot;)
                 if hostname in f.read():
                     self.found.emit(hostname)
                 else:
                     self.notFound.emit(hostname)
             self.finished.emit()   
              
     def stop(self):
         self.keepRunning = False
         self.queue.put(None)
  
  
     def lookUp(self, hostname):
         self.queue.put(hostname)
  </code></pre>