日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python 线程类 threading.Thread.join() 方法 (自闭,不让别人进来了)

發布時間:2025/3/19 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 线程类 threading.Thread.join() 方法 (自闭,不让别人进来了) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
def join(self, timeout=None):"""Wait until the thread terminates. 等待線程終止。This blocks the calling thread until the thread whose join() method iscalled terminates -- either normally or through an unhandled exceptionor until the optional timeout occurs.這會阻塞調用線程,直到其join()方法被調用的線程終止(正常或通過未處理的異常終止),或直到發生可選的超時為止。When the timeout argument is present and not None, it should be afloating point number specifying a timeout for the operation in seconds(or fractions thereof). As join() always returns None, you must callisAlive() after join() to decide whether a timeout happened -- if thethread is still alive, the join() call timed out.如果存在timeout參數而不是None,則它應該是一個浮點數,以秒(或其分數)指定操作的超時時間。 由于join()始終返回None,因此必須在join()之后調用isAlive()來確定是否發生超時-如果線程仍處于活動狀態,則join()調用將超時。When the timeout argument is not present or None, the operation willblock until the thread terminates.當不存在超時參數或timeout==None,該操作將阻塞直到線程終止。A thread can be join()ed many times.一個線程可以被多次join()。join() raises a RuntimeError if an attempt is made to join the currentthread as that would cause a deadlock. It is also an error to join() athread before it has been started and attempts to do so raises the sameexception.如果嘗試加入當前線程,join()可能會引發RuntimeError,因為可能導致死鎖。 在啟動線程之前join()一個線程也是錯誤的,嘗試這樣做會引發相同的異常。"""if not self._initialized:raise RuntimeError("Thread.__init__() not called")if not self._started.is_set():raise RuntimeError("cannot join thread before it is started")if self is current_thread():raise RuntimeError("cannot join current thread")if timeout is None:self._wait_for_tstate_lock()else:# the behavior of a negative timeout isn't documented, but# historically .join(timeout=x) for x<0 has acted as if timeout=0# 沒有記錄負超時的行為,但是歷史上.x(0)的.join(timeout = x)表現為超時= 0self._wait_for_tstate_lock(timeout=max(timeout, 0))

總結

以上是生活随笔為你收集整理的python 线程类 threading.Thread.join() 方法 (自闭,不让别人进来了)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。