I have a class A extended from threading.Thread, now I want to pass the parameters into the running thread , I can get the thread I wanted by the following script:
find_thread = None
for thread in enumerate():
if thread.isAlive():
name = thread.name.split(',')[-1]
if name == player_id:
find_thread = thread #inject the parameter into this thread
break
Where find_thread is an instance of threading.Thread and I have a queue in find_thread.
class A(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue =queue
def run():
if not self.queue.empty(): #when it's running,I want to pass the parameters here
a=queue.get()
process(a) #do something
Is it possible to do this and how?
queueand have aqueue.get(recommendget_nowait()instead). So why not just usequeue.put_nowait()from whatever thread you want to and haveAleverage thequeue.get()you have?