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,128 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

0 votes
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,040 points
184,424 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,478 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,910 points
1,475 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,450 points
1,246 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,058 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,073 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,520 points
105,339 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