Bottom Page

Thread Rating:
  • 3 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Need help with threads in for loop
Hello Friends,

I am using a nested loop first loop iterate for 50,000 times and second loop iterate for 500 times if i use normal approach
for i in range(0,50000):
    for j in range(0,250)
It is taking huge time so can any one tell me how can i execute this nested for loop faster? can you please share the code as well

i am using this code but not very much fast.

import time

from threading import Thread

class GetMyThread(Thread):
    def __init__(self, start, end, start2, end2):
        self.ix = start 
        self.iy= end
        self.jx = start2
        self.jy = end2
        super(GetMyThread, self).__init__()
        for i in range(self.ix, self.iy):
            for j in range(0, len(overallKeywordsFrequency)):
                    if(overallKeywordsFrequency[j] in (df.iloc[i]['Keywords'].lower().strip())):
                        matrix[i,j] = 1

def get_responses():
    start = time.time()
    threads = []
    num_splits = 50
    split_size = len(df)//num_splits
    split_size2 = len(overallKeywordsFrequency)//num_splits
    for i in  range(num_splits):
        start = i * split_size
        start2 = i * split_size2
        end = len(df) if i+1 == num_splits else (i+1) * split_size
        end2 = len(overallKeywordsFrequency) if i+1 == num_splits else (i+1) * split_size2
        t = GetMyThread(start, end, start2, end2)
    for t in threads:

buran wrote Jan-11-2019, 12:50 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
I have the suspicion that your code is taking an exceedingly long time due to a bug. The GetMyThread.__init__() method is running the matrix loop. Properly, that loop should be in the method instead. I say this because you later call the thread.join() method and that method listens for the termination of the method according to the documentation. If the method isn't being used, thread.join() should not work. In turn, that means that you have a thread running and the program isn't stopping to collect its data.

Also, I don't see any mechanism for collecting the data from the thread.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Com Error with macro within for loop due to creating new workbook in the loop Lastwizzle 0 33 May-18-2019, 09:29 PM
Last Post: Lastwizzle
  Python threads and aircrack-ng adam2020 2 131 Apr-01-2019, 08:54 PM
Last Post: adam2020
  Threads join() question adam2020 4 163 Mar-19-2019, 09:30 PM
Last Post: adam2020
  Question about for loop not creating an infinite loop. FWendeburg 1 187 Feb-03-2019, 08:45 PM
Last Post: ichabod801
  loop through list or double loop 3Pinter 4 373 Dec-05-2018, 06:17 AM
Last Post: 3Pinter
  stop multiple threads jeuvrey 5 447 Nov-15-2018, 01:34 PM
Last Post: jeuvrey
  Handling Many Threads. MuntyScruntfundle 3 353 Oct-17-2018, 05:07 PM
Last Post: stranac
  Quitting multiple threads MuntyScruntfundle 3 327 Oct-17-2018, 05:14 AM
Last Post: volcano63
  Threads in threads? MuntyScruntfundle 1 319 Oct-14-2018, 09:10 AM
Last Post: Gribouillis
  starting multi threads MuntyScruntfundle 7 536 Oct-11-2018, 08:52 PM
Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)