Python threading and handing over values
<p>Im trying to update threads which continuously run with new values every now and then.</p>

<pre><code>class Test:
    def __init__(self, num):
        #testing reasons
        self.num = num

    def printloop(self, num):
        self.num = num
        #running is set to True sometime in the beginning   
        while running:
            print(self.num)
            time.sleep(3)
        if not running:
            print("finished")
    def setnum(self, num):
        self.num = num
</code></pre>

<p>I create threads like this:</p>

<pre><code>t1 = threading.Thread(target=test.printloop,args=("1"))
</code></pre>

<p>This works and prints the proper arg.</p>

<p>But how can I update single threads with new values - if needed? Not all of the threads might need to be updated. The setnum method in my class there is obviously not working since it would update the value for all of the threads.</p>

<p>Do I need to limit the thread lifetime and join and wait for them to finish. Then recreating them with new values? 
Or should I define a variable for each thread - how do I do that dynamically?
Or is there a better way im not seeing?
Thanks!</p>

<p>Edit:</p>

<p>I suppose i'll end up with something like:</p>

<pre><code>test1 = Test(1)
..
test5 = Test(5)

t1 = threading.Thread(target=test1.printloop,args=("1"))
t5 = threading.Thread(target=test5.printloop,args=("5"))
</code></pre>

<p>and then use a method on each to set the Values?</p>
