how to run list of functions using Thread

+1 vote

We have a file called functions.py and in that list f has 4 functions like :

f = [f1,f2,f3,f4]

which f[0]() call f1! the question is to call every list member using Thread and put the code in solve function ! but two notes are important :

  1. Call all of members in on time!
  2.  Threads could be not same as the others.
def solve(f):
    th=[]
    for i in range(4):
        x = threading.Thread(target=f)
        x.start()
        th.append(x)
    for anyt,j in enumerate(th):
        j.join()

What's the problem? could anyone helps me?

Aug 24, 2019 in Python by Andres
1,610 views

1 answer to this question.

0 votes

You could import the file with function onto the file where you're calling them in the solve function. 

import functions.py
def solve(f)
threads = list()
    for index in range(4):
        x = threading.Thread(target=thread_function, args=(index,))
        threads.append(x)
        x.start()
answered Aug 26, 2019 by Vishaka

Related Questions In Python

+1 vote
4 answers

how to sort a list of numbers without using built-in functions like min, max or any other function?

Yes it is possible. You can refer ...READ MORE

answered Jun 27, 2019 in Python by Arvind
• 3,050 points
188,543 views
0 votes
1 answer

Using list comprehension how to call list of function

For the class method when used as ...READ MORE

answered Nov 14, 2018 in Python by Theodor
• 740 points
3,769 views
0 votes
1 answer

how to run test cases of different modules with same marker at a time using pytest

Hey,@Nikitha, Suppose you have multiple files say test_sample1.py, test_sample2.py. To ...READ MORE

answered Apr 28, 2020 in Python by Gitika
• 65,770 points
1,786 views
0 votes
1 answer

How to sort a list of strings?

Basic answer: mylist = ["b", "C", "A"] mylist.sort() This modifies ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,460 points
1,507 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,455 views
0 votes
1 answer
0 votes
1 answer

How to get the multiplication table of any number using list comprehension?

Hey @Neha, you can use something like ...READ MORE

answered Jul 8, 2019 in Python by Sakshi
6,701 views
0 votes
3 answers

How to get the return value from a thread using python?

FWIW, the multiprocessing module has a nice interface for ...READ MORE

answered Dec 15, 2020 in Python by Roshni
• 10,480 points
107,891 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP