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 in Python by Andres
18 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 by Vishaka

Related Questions In Python

0 votes
1 answer
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
173 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 ariaholic
• 7,340 points
38 views
0 votes
1 answer

How to sort a list of strings?

Try  items = ["live", "like", "code", "cool", "bug"] ...READ MORE

answered Jul 27, 2018 in Python by Priyaj
• 56,540 points
24 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 236 views
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 in Python by Sakshi
34 views
0 votes
1 answer

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

You don't need to change your existing ...READ MORE

answered Dec 3, 2018 in Python by Nymeria
• 3,520 points

edited Dec 19, 2018 by Nymeria 10,281 views