0

in my project i have a class of threading.Thread like this:

class MakeHtml(threading.Thread):
    def __init__(self, *rstext):
        self.outhtml = [x for x in rstext]
        self.retval = ''
        threading.Thread.__init__(self)

    def run(self):
        ...do something

in another file i call, every 10 seconds MakeHtml class

t = MakeHtml(mrr1, mrr2, mrr3, mrr4)

for create a thread but in this way i see that the thread is the same every time.

I need a new thread every time i call the MakeHtml Threading class, how can i do this?

Thanks in advance

0

1 Answer 1

1

MakeHtml extends Thread, but if you have only 1 instance of MakeHtml, you will have only one thread

For instance if you want 2 different thread you will have to do

t = MakeHtml(mrr1, mrr2, mrr3, mrr4) # one thread
t1 = MakeHtml(mrr1, mrr2, mrr3, mrr4) # another one

You can use :

import threading

def afunction(mm):
   # do job
   pass

threads = []
for mm in [mmr1, mmr2, mmr3n mmr4]:
    t = threading.Thread(target=afunction, args=[mm,])
    threads.append(t)
    t.start()
[t.join() for t in threads]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.