@@ -673,7 +673,7 @@ msgstr ""
673673
674674#: ../../library/threading.rst:503
675675msgid "Lock Objects"
676- msgstr ""
676+ msgstr "Lock 物件 "
677677
678678#: ../../library/threading.rst:505
679679msgid ""
@@ -682,6 +682,9 @@ msgid ""
682682"synchronization primitive available, implemented directly by the :mod:"
683683"`_thread` extension module."
684684msgstr ""
685+ "原始鎖 (primitive lock) 是一種同步原語 (synchronization primitive),在鎖定時"
686+ "不屬於特定執行緒。在 Python 中,它是目前可用的最低階同步原語,直接由 :mod:"
687+ "`_thread` 擴充模組實作。"
685688
686689#: ../../library/threading.rst:510
687690msgid ""
@@ -696,10 +699,18 @@ msgid ""
696699"state to unlocked and returns immediately. If an attempt is made to release "
697700"an unlocked lock, a :exc:`RuntimeError` will be raised."
698701msgstr ""
702+ "原始鎖會處於兩種狀態之一:「鎖定 (locked)」或「未鎖定 (unclocked)」,建立時會"
703+ "處於未鎖定狀態。它有兩個基本方法 :meth:`~Lock.acquire` 和 :meth:`~Lock."
704+ "release`。當狀態為未鎖定時,:meth:`~Lock.acquire` 會將狀態變更為鎖定並立即回"
705+ "傳。當狀態被鎖定時,:meth:`~Lock.acquire` 會阻塞 (block),直到另一個執行緒中"
706+ "對 :meth:`~Lock.release` 的呼叫將其更改為未鎖定狀態,然後 :meth:`~Lock."
707+ "acquire` 呼叫會將其重置為鎖定並回傳。:meth:`~Lock.release` 方法只能在鎖定狀態"
708+ "下呼叫;它將狀態更改為未鎖定並立即回傳。如果嘗試釋放未鎖定的鎖,則會引發 :"
709+ "exc:`RuntimeError`。"
699710
700711#: ../../library/threading.rst:521
701712msgid "Locks also support the :ref:`context management protocol <with-locks>`."
702- msgstr ""
713+ msgstr "鎖也支援 \\ :ref:`情境管理協定 <with-locks>`。 "
703714
704715#: ../../library/threading.rst:523
705716msgid ""
@@ -708,40 +719,52 @@ msgid ""
708719"release` call resets the state to unlocked; which one of the waiting threads "
709720"proceeds is not defined, and may vary across implementations."
710721msgstr ""
722+ "當多個執行緒阻塞在 :meth:`~Lock.acquire` 中等待狀態轉變為未鎖定,此時若呼叫 :"
723+ "meth:`~Lock.release` 將狀態重置為未鎖定,則只會有一個執行緒繼續進行;哪一個等"
724+ "待執行緒會繼續進行是未定義的,並且可能因實作而異。"
711725
712726#: ../../library/threading.rst:528
713727msgid "All methods are executed atomically."
714- msgstr ""
728+ msgstr "所有方法均以最小不可分割的操作方式 (atomically) 執行。 "
715729
716730#: ../../library/threading.rst:533
717731msgid ""
718732"The class implementing primitive lock objects. Once a thread has acquired a "
719733"lock, subsequent attempts to acquire it block, until it is released; any "
720734"thread may release it."
721735msgstr ""
736+ "實作原始鎖物件的類別。一旦執行緒獲得了鎖,後續再嘗試獲得它就會被阻塞,直到鎖"
737+ "被釋放;任何執行緒都可以去釋放它。"
722738
723739#: ../../library/threading.rst:537
724740msgid ""
725741"``Lock`` is now a class. In earlier Pythons, ``Lock`` was a factory function "
726742"which returned an instance of the underlying private lock type."
727743msgstr ""
744+ "``Lock`` 現在是一個類別。在早期的 Python 中,``Lock`` 是一個會回傳底層私有鎖"
745+ "型別實例的工廠函式。"
728746
729747#: ../../library/threading.rst:545 ../../library/threading.rst:636
730748msgid "Acquire a lock, blocking or non-blocking."
731- msgstr ""
749+ msgstr "阻塞或非阻塞地取得鎖。 "
732750
733751#: ../../library/threading.rst:547
734752msgid ""
735753"When invoked with the *blocking* argument set to ``True`` (the default), "
736754"block until the lock is unlocked, then set it to locked and return ``True``."
737755msgstr ""
756+ "當以 *blocking* 引數設為 ``True``\\ (預設值)來調用,將會阻塞直到鎖被解鎖,"
757+ "然後將其設為鎖定並回傳 ``True``。"
738758
739759#: ../../library/threading.rst:550
740760msgid ""
741761"When invoked with the *blocking* argument set to ``False``, do not block. If "
742762"a call with *blocking* set to ``True`` would block, return ``False`` "
743763"immediately; otherwise, set the lock to locked and return ``True``."
744764msgstr ""
765+ "當以 *blocking* 引數設為 ``False`` 調用則不會阻塞。如果 *blocking* 設定為 "
766+ "``True`` 的呼叫會阻塞,則立即回傳 ``False``;否則將鎖設為鎖定並回傳 "
767+ "``True``。"
745768
746769#: ../../library/threading.rst:554
747770msgid ""
@@ -751,48 +774,55 @@ msgid ""
751774"specifies an unbounded wait. It is forbidden to specify a *timeout* when "
752775"*blocking* is ``False``."
753776msgstr ""
777+ "當使用設定為正值的浮點 *timeout* 引數進行調用,只要持續無法取得鎖,最多會阻"
778+ "塞 *timeout* 指定的秒數。``-1`` 的 *timeout* 引數代表指定為不會停止的等待。"
779+ "當 *blocking* 為 ``False`` 時禁止指定 *timeout*。"
754780
755781#: ../../library/threading.rst:560
756782msgid ""
757783"The return value is ``True`` if the lock is acquired successfully, ``False`` "
758784"if not (for example if the *timeout* expired)."
759785msgstr ""
786+ "如果成功取得鎖,則回傳值為 ``True``,否則回傳值為 ``False``\\ (例如像是 "
787+ "*timeout* 已逾期)。"
760788
761789#: ../../library/threading.rst:563 ../../library/threading.rst:674
762790#: ../../library/threading.rst:921
763791msgid "The *timeout* parameter is new."
764- msgstr ""
792+ msgstr "新的 *timeout* 參數。 "
765793
766794#: ../../library/threading.rst:566
767795msgid ""
768796"Lock acquisition can now be interrupted by signals on POSIX if the "
769797"underlying threading implementation supports it."
770- msgstr ""
798+ msgstr "如果底層執行緒實作支援的話,鎖的獲取現在可以被 POSIX 上的訊號中斷。 "
771799
772800#: ../../library/threading.rst:573
773801msgid ""
774802"Release a lock. This can be called from any thread, not only the thread "
775803"which has acquired the lock."
776- msgstr ""
804+ msgstr "釋放鎖。這可以從任何執行緒呼叫,而不是只有獲得鎖的執行緒。 "
777805
778806#: ../../library/threading.rst:576
779807msgid ""
780808"When the lock is locked, reset it to unlocked, and return. If any other "
781809"threads are blocked waiting for the lock to become unlocked, allow exactly "
782810"one of them to proceed."
783811msgstr ""
812+ "當鎖被鎖定時,將其重置為未鎖定然後回傳。如果任何其他執行緒在等待鎖被解鎖時被"
813+ "阻塞,只允許其中一個執行緒繼續進行。"
784814
785815#: ../../library/threading.rst:580
786816msgid "When invoked on an unlocked lock, a :exc:`RuntimeError` is raised."
787- msgstr ""
817+ msgstr "當在未鎖定的鎖上調用時,會引發 :exc:`RuntimeError` "
788818
789819#: ../../library/threading.rst:582 ../../library/threading.rst:690
790820msgid "There is no return value."
791- msgstr ""
821+ msgstr "沒有回傳值。 "
792822
793823#: ../../library/threading.rst:586
794824msgid "Return ``True`` if the lock is acquired."
795- msgstr ""
825+ msgstr "如果有取得了鎖,則回傳 ``True``。 "
796826
797827#: ../../library/threading.rst:593
798828msgid "RLock Objects"
@@ -806,12 +836,18 @@ msgid ""
806836"state used by primitive locks. In the locked state, some thread owns the "
807837"lock; in the unlocked state, no thread owns it."
808838msgstr ""
839+ "可重入鎖 (reentrant lock) 是一種同步原語,同一執行緒可以多次取得它。在內部,"
840+ "除了原始鎖使用的鎖定/未鎖定狀態之外,它還使用「所屬執行緒 (owning thread)」和"
841+ "「遞迴等級 (recursion level)」的概念。在鎖定狀態下,某個執行緒會擁有鎖;在未"
842+ "鎖定狀態下則沒有執行緒擁有它。"
809843
810844#: ../../library/threading.rst:601
811845msgid ""
812846"Threads call a lock's :meth:`~RLock.acquire` method to lock it, and its :"
813847"meth:`~Lock.release` method to unlock it."
814848msgstr ""
849+ "執行緒呼叫鎖的 :meth:`~RLock.acquire` 方法來鎖定它,並呼叫它的 :meth:`~Lock."
850+ "release` 方法來解鎖它。"
815851
816852#: ../../library/threading.rst:606
817853msgid ""
@@ -820,6 +856,9 @@ msgid ""
820856"meth:`~RLock.acquire` and :meth:`~RLock.release` to handle acquiring and "
821857"releasing the lock for a block of code."
822858msgstr ""
859+ "可重入鎖支援\\ :ref:`情境管理協定<with-locks>`,因此建議使用 :keyword:`with` "
860+ "而不是手動呼叫 :meth:`~RLock.acquire` 和 :meth:`~RLock.release` 來對程式碼區"
861+ "塊處理鎖的獲得和釋放。"
823862
824863#: ../../library/threading.rst:611
825864msgid ""
@@ -829,6 +868,10 @@ msgid ""
829868"pair) resets the lock to an unlocked state and allows another thread blocked "
830869"in :meth:`~RLock.acquire` to proceed."
831870msgstr ""
871+ "RLock 的 :meth:`~RLock.acquire`/:meth:`~RLock.release` 呼叫成對組合可以嵌套使"
872+ "用,這與 Lock 的 :meth:`~Lock.acquire`/:meth:`~Lock.release` 不同。只有最後一"
873+ "個 :meth:`~RLock.release`\\ (最外面一對的 :meth:`~Lock.release`)會將鎖重置"
874+ "為未鎖定狀態,並允許在 :meth:`~RLock.acquire` 中阻塞的另一個執行緒繼續進行。"
832875
833876#: ../../library/threading.rst:617
834877msgid ""
@@ -837,6 +880,9 @@ msgid ""
837880"Failing to call release as many times the lock has been acquired can lead to "
838881"deadlock."
839882msgstr ""
883+ ":meth:`~RLock.acquire`/:meth:`~RLock.release` 必須成對使用:每次獲得都必須在"
884+ "已獲得鎖的執行緒中有一個釋放。如果鎖釋放的次數不能和獲取的次數一樣的話,可能"
885+ "會導致死鎖 (deadlock)。"
840886
841887#: ../../library/threading.rst:624
842888msgid ""
@@ -845,38 +891,47 @@ msgid ""
845891"reentrant lock, the same thread may acquire it again without blocking; the "
846892"thread must release it once for each time it has acquired it."
847893msgstr ""
894+ "此類別實作了可重入鎖物件。可重入鎖必須由獲得它的執行緒釋放。一旦一個執行緒獲"
895+ "得了可重入鎖,同一個執行緒可以再次獲得它而不會阻塞;執行緒每次獲得它也都必須"
896+ "釋放它一次。"
848897
849898#: ../../library/threading.rst:629
850899msgid ""
851900"Note that ``RLock`` is actually a factory function which returns an instance "
852901"of the most efficient version of the concrete RLock class that is supported "
853902"by the platform."
854903msgstr ""
904+ "請注意,``RLock`` 實際上是一個工廠函式,它會回傳平台有支援的特定 RLock 類別的"
905+ "最高效率版本的實例。"
855906
856907#: ../../library/threading.rst:640
857908msgid ":ref:`Using RLock as a context manager <with-locks>`"
858- msgstr ""
909+ msgstr ":ref:`將 RLock 用作為情境管理器 <with-locks>` "
859910
860911#: ../../library/threading.rst:641
861912msgid ""
862913"Recommended over manual :meth:`!acquire` and :meth:`release` calls whenever "
863914"practical."
864915msgstr ""
916+ "若是使用場景合理,和手動呼叫 :meth:`!acquire` 和 :meth:`release` 相比,會是更"
917+ "為推薦的使用方式。"
865918
866919#: ../../library/threading.rst:645
867920msgid ""
868921"When invoked with the *blocking* argument set to ``True`` (the default):"
869- msgstr ""
922+ msgstr "當以 *blocking* 引數設為 ``True`` \\ (預設值)來調用: "
870923
871924#: ../../library/threading.rst:647 ../../library/threading.rst:659
872925msgid "If no thread owns the lock, acquire the lock and return immediately."
873- msgstr ""
926+ msgstr "如果沒有執行緒擁有鎖,則獲得鎖並立即回傳。 "
874927
875928#: ../../library/threading.rst:649
876929msgid ""
877930"If another thread owns the lock, block until we are able to acquire lock, or "
878931"*timeout*, if set to a positive float value."
879932msgstr ""
933+ "如果另一個執行緒擁有鎖,則阻塞直到能夠取得鎖,或者達到 *timeout*\\ (如果設定"
934+ "為正浮點值)。"
880935
881936#: ../../library/threading.rst:652
882937msgid ""
@@ -885,34 +940,41 @@ msgid ""
885940"RLock`; :class:`Lock` handles this case the same as the previous, blocking "
886941"until the lock can be acquired."
887942msgstr ""
943+ "如果同一個執行緒擁有鎖,則再次取得鎖,並立即回傳。這就是 :class:`Lock` 和 :"
944+ "class:`!RLock` 之間的差別;:class:`Lock` 處理方式與上一種情況相同,會阻塞直到"
945+ "能夠取得鎖。"
888946
889947#: ../../library/threading.rst:657
890948msgid "When invoked with the *blocking* argument set to ``False``:"
891- msgstr ""
949+ msgstr "當以 *blocking* 引數設為 ``False`` 來調用: "
892950
893951#: ../../library/threading.rst:661
894952msgid "If another thread owns the lock, return immediately."
895- msgstr ""
953+ msgstr "如果另一個執行緒擁有該鎖,則立即回傳。 "
896954
897955#: ../../library/threading.rst:663
898956msgid ""
899957"If the same thread owns the lock, acquire the lock again and return "
900958"immediately."
901- msgstr ""
959+ msgstr "如果同一個執行緒擁有鎖,則再次取得鎖並立即回傳。 "
902960
903961#: ../../library/threading.rst:666
904962msgid ""
905963"In all cases, if the thread was able to acquire the lock, return ``True``. "
906964"If the thread was unable to acquire the lock (i.e. if not blocking or the "
907965"timeout was reached) return ``False``."
908966msgstr ""
967+ "在所有情況下,如果執行緒能夠取得鎖則回傳 ``True``。如果執行緒無法取得鎖(即沒"
968+ "有阻塞或已達超時限制)則回傳 ``False``。"
909969
910970#: ../../library/threading.rst:670
911971msgid ""
912972"If called multiple times, failing to call :meth:`~RLock.release` as many "
913973"times may lead to deadlock. Consider using :class:`!RLock` as a context "
914974"manager rather than calling acquire/release directly."
915975msgstr ""
976+ "如果多次呼叫,又未能呼叫相同次數的 :meth:`~RLock.release`,則可能會導致死鎖。"
977+ "考慮將 :class:`!RLock` 作為情境管理器使用,而不是直接呼叫 acquire/release。"
916978
917979#: ../../library/threading.rst:680
918980msgid ""
@@ -922,13 +984,18 @@ msgid ""
922984"exactly one of them to proceed. If after the decrement the recursion level "
923985"is still nonzero, the lock remains locked and owned by the calling thread."
924986msgstr ""
987+ "釋放鎖並減少遞迴等級。如果被減至零,則將鎖重置為未鎖定(不屬於任何執行緒),"
988+ "並且如果任何其他執行緒被阻塞以等待鎖變成未鎖定狀態,則僅允許其中一個執行緒繼"
989+ "續進行。如果遞減後遞迴等級仍然非零,則鎖會保持鎖定並由呼叫它的執行緒所擁有。"
925990
926991#: ../../library/threading.rst:686
927992msgid ""
928993"Only call this method when the calling thread owns the lock. A :exc:"
929994"`RuntimeError` is raised if this method is called when the lock is not "
930995"acquired."
931996msgstr ""
997+ "僅當呼叫的執行緒擁有鎖時才能呼叫此方法。如果在未取得鎖時呼叫此方法則會引發 :"
998+ "exc:`RuntimeError`。"
932999
9331000#: ../../library/threading.rst:696
9341001msgid "Condition Objects"
0 commit comments