所以基本上我的目标是为每个handlerId
启动并继续运行一个线程。在我的主线程中,我有以下代码:
handlerId = rcvd_dict['handlerId']
if handlerId not in thread_dict: #start a new thread, storing it in thread_dict
new_thread = threading.Thread(target = request_thread(ws, rcvd_dict))
thread_dict[handlerId] = new_thread
thread_dict[handlerId].start()
else: #return to the specific thread already existing also passing the argument
'rcvd_dict' that is a dictionary with information for the thread to run
每个线程开始执行以下功能:
def request_thread(ws, rcvd_dict):
#do something with the dictionary 'rcvd_dict' received as argument
我想保持同一线程的运行状态,该线程可能会收到数本字典来处理它。我想在执行一次之后使线程“休眠”,并且仅在我想使用另一个“ rcvd_dict”字典参数再次调用它之后才恢复/重新开始执行。我想到了线程函数中的一个循环,但是如何定义主线程和每个子线程之间的条件?使用Python可以轻松做到这一点吗?