I am learning Python (3.6) and I am writing some code in a functional style (not using classes) - I have functions which are started as daemon threads by a manager() function.
I need to start an additional function in its own thread, that is passed arguments from within one of the functions that is started by the manager function as a daemon thread, as it throws an exception if it is started from within the manager function, as the argument which it expects does not exist when it is started...
Here is a representation of my code and the problem I am having - I want to be able to start func4 in its own thread and pass it an argument from within func3... func3 will call func4 a large number of times, so I need the thread in which func4 runs to die as soon as soon as the code completes...
import threading
threads = []
def func1():
// runs in its own thread and receives messages from a message queue
def func2():
// runs in its own thread and sends messages in a loop to a message queue
def func3():
// runs in its own thread and receives messages from a message queue, does some
// processing, assigns values to a variable then passes variable to func4
def func4(passed_variable_from func3):
// performs actions on variable passed from func3 and I would like it to
// run in its own thread... IS THIS POSSIBLE?
def manager():
# Thread t1
t1 = threading.Thread(target=func1)
t1.daemon = True
threads.append(t1)
# Thread t2
t2 = threading.Thread(target=func2)
t2.daemon = True
threads.append(t2)
t2.start()
# Thread t3
t3 = threading.Thread(target=func3)
t3.daemon = True
threads.append(t3)
t3.start()
t1.start()
for t in threads:
t.join()
manager()