1
response = [['[common]'], ['[webui]'], ['[webui]', '[debug]', 'msgq']]
def checkline(self,each_response, line, queue ):
    if all(w in line for w in each_response):
        queue.put(True)
    else:
        queue.put(False)
with open(debugfile, "r") as in_file:                             
    if bool(response):
        threads = []
        final = []
        for i_response in range(len(response)):
            queued_request = Queue.Queue()
            t = threading.Thread(target=self.checkline, args(response[i_response],line.lower(),queued_request,))
            threads.append(t)
            t.start()

        final.append(queued_request.get())
        for x in threads:
            x.join()
        print final
        if True in final:
            print line

Here i am looking to start all the threads at the same time in order to reduce the execution time. Please any suggestions?

PAR
  • 624
  • 1
  • 5
  • 16
  • I don't think what you're asking is possible, since all the threads are started from a single process, which is, by definition, sequential. – roelofs Nov 29 '17 at 10:28
  • The thread spawning process should be quick enough - it's much more likely that your execution time will depend on what's happening inside the threads. – roelofs Nov 29 '17 at 10:29
  • you could perform the start of the threads after your first loop instead of inside. the start of the threads would be more "simultaneous". but I fail to see the interest – Jean-François Fabre Nov 29 '17 at 10:31
  • 1
    yes, creating threads is useless for pure python code, since python has a GIL (global interpreter lock) which makes the threads run one at a time. – Jean-François Fabre Nov 29 '17 at 10:32
  • Thankyou. Is there any other alternative approach please suggest me. Just i need to check whether all each_response are present in each line. Because when my response is increased it takes lot of time for execution. – PAR Nov 29 '17 at 10:35

0 Answers0