I need to run two functions with the threading
module
you’re able to do this Thread(target=my_func)
but i want the function from a class (imported class) so i tried Thread(target=a_class.my_func)
but it didn’t worked, then i tried Thread(target=a_class.my_func())
but this one starts to run the function because i called it , and this is an infinite loop so the next function would never run.
how do i supposed to do it?
Advertisement
Answer
You should wrap the class methods, like this:
JavaScript
x
11
11
1
import threading
2
3
def my_func(self):
4
a_class.my_func()
5
6
def my_other_func(self):
7
a_class.my_other_func()
8
9
t1 = threading.Thread(target=my_func)
10
t2 = threading.Thread(target=my_other_func)
11