I have sample dictionary is below
- I need to find the count of each attribute
- I need to implement using multithreading
- total(todos) is the main function. In this there are 3 other functions called. which i need to implement using multithreading. Right now first it will do sequentially like first it will do userid_count(todos) followed by title_count(todos) and complete_count(todos). Since each of these function is independent of each other I need to do with multithreading/multiprocessing
todos = [{'userId': 1, 'id': 1, 'title': 'A', 'completed': False},
{'userId': 1, 'id': 2, 'title': 'B ', 'completed': False},
{'userId': 1, 'id': 1, 'title': 'C', 'completed': False},
{'userId': 1, 'id': 2, 'title': 'A', 'completed': True},
{'userId': 2, 'id': 1,'title': 'B', 'completed': False}]
def total(todos):
user_count = userid_count(todos)
###### Multithreading need to implement ##########
title = title_count(todos)
completed = complete_count(todos)
search_count_all = {**user_count, **title, **completed}
return search_count_all
def userid_count(todos)
#return userid count there are 2 user id 1, 2
#{"userid":2}
pass
def title_count(todos)
#return title count there are 3 title A, B, C
#{"title":3}
pass
def complete_count(todos)
#return completed count there are Tru and False
#{"True": 1, "False":3}
pass
total(todos)
Expected out is
[{"userid":2},{"title":3},{"True": 1, "False":3} ]
question from:
https://stackoverflow.com/questions/65558270/how-to-do-multithreading-or-multiprocessing-while-calling-function-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…