1
我定義如下兩個功能:的Python的Thread.join(時間)回不回
功能,使一個線程:
def join_group_thread(client, link):
thread_queue = queue.Queue()
thread_1 = threading.Thread(
target=join_group,
name="Join Group Thread",
args=[client, link, thread_queue],
)
thread_1.start()
thread_1.join(10)
return thread_queue.get()
功能,在線程中運行:
def join_group(client, params, queue):
try:
response = client.invoke(ImportChatInviteRequest(params))
except Exception as e:
response = str(e).replace("'","")
queue.put(response)
在main()
我打電話join_group_thread
這樣的:
result = join_group_thread(client, link)
由於我在這裏設定時間爲10秒,因此我預計result = join_group_thread(client, link)
最多需要10秒,但有時會永久掛起。
任何解釋?