Currently I'm working on a Python script that essentially acts as a search tool, where I have a list containing thousands of strings, and I split this list into smaller lists where each of them are sent to a QThread to be searched.
For example, the variable 'items' contains all of the strings. I split this list into smaller lists for every 100,000 items, by doing the following:
split_lists = [items[x:x+100000] for x in range(0, len(items), 100000)]
Next, I send each small list to my QThread worker class to be searched for e.g. a keyword:
keyword = "Hello"
for i in range(len(split_lists)):
item_searcher = ItemSearcher(split_list[i], keyword)
Essentially, this would speed up the search by searching different parts of the main list concurrently, rather than searching the entire main list in the main thread.
My QThread worker class (ItemSearcher) is as follows:
class ItemSearcher(QtCore.QThread):
def __init__(self, itemList, searchKeyword):
"""
Constructor
"""
super().__init__()
# Initialize fields
self.item_list = itemList
self.search_keyword = searchKeyword
def run(self):
for item in self.item_list:
if self.search_keyword in item:
# Item found
print(item)
As of right now, the script just finishes executing immediately without any output and seems like the QThread is not working as it should. I'm fairly new to working with QThread, so any tips or suggestions on how to get the QThread to work would be much appreciated.
ItemSearcher? - ניר