Skip to content

Commit

Permalink
Merge pull request #985 from mattwang44/threading-lock
Browse files Browse the repository at this point in the history
  • Loading branch information
josix authored Oct 8, 2024
2 parents fabbfa0 + 8c391a3 commit 7949b02
Showing 1 changed file with 83 additions and 16 deletions.
99 changes: 83 additions & 16 deletions library/threading.po
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ msgstr ""

#: ../../library/threading.rst:503
msgid "Lock Objects"
msgstr ""
msgstr "Lock 物件"

#: ../../library/threading.rst:505
msgid ""
Expand All @@ -682,6 +682,9 @@ msgid ""
"synchronization primitive available, implemented directly by the :mod:"
"`_thread` extension module."
msgstr ""
"原始鎖 (primitive lock) 是一種同步原語 (synchronization primitive),在鎖定時"
"不屬於特定執行緒。在 Python 中,它是目前可用的最低階同步原語,直接由 :mod:"
"`_thread` 擴充模組實作。"

#: ../../library/threading.rst:510
msgid ""
Expand All @@ -696,10 +699,18 @@ msgid ""
"state to unlocked and returns immediately. If an attempt is made to release "
"an unlocked lock, a :exc:`RuntimeError` will be raised."
msgstr ""
"原始鎖會處於兩種狀態之一:「鎖定 (locked)」或「未鎖定 (unclocked)」,建立時會"
"處於未鎖定狀態。它有兩個基本方法 :meth:`~Lock.acquire` 和 :meth:`~Lock."
"release`。當狀態為未鎖定時,:meth:`~Lock.acquire` 會將狀態變更為鎖定並立即回"
"傳。當狀態被鎖定時,:meth:`~Lock.acquire` 會阻塞 (block),直到另一個執行緒中"
"對 :meth:`~Lock.release` 的呼叫將其更改為未鎖定狀態,然後 :meth:`~Lock."
"acquire` 呼叫會將其重置為鎖定並回傳。:meth:`~Lock.release` 方法只能在鎖定狀態"
"下呼叫;它將狀態更改為未鎖定並立即回傳。如果嘗試釋放未鎖定的鎖,則會引發 :"
"exc:`RuntimeError`。"

#: ../../library/threading.rst:521
msgid "Locks also support the :ref:`context management protocol <with-locks>`."
msgstr ""
msgstr "鎖也支援\\ :ref:`情境管理協定 <with-locks>`。"

#: ../../library/threading.rst:523
msgid ""
Expand All @@ -708,40 +719,52 @@ msgid ""
"release` call resets the state to unlocked; which one of the waiting threads "
"proceeds is not defined, and may vary across implementations."
msgstr ""
"當多個執行緒阻塞在 :meth:`~Lock.acquire` 中等待狀態轉變為未鎖定,此時若呼叫 :"
"meth:`~Lock.release` 將狀態重置為未鎖定,則只會有一個執行緒繼續進行;哪一個等"
"待執行緒會繼續進行是未定義的,並且可能因實作而異。"

#: ../../library/threading.rst:528
msgid "All methods are executed atomically."
msgstr ""
msgstr "所有方法均以最小不可分割的操作方式 (atomically) 執行。"

#: ../../library/threading.rst:533
msgid ""
"The class implementing primitive lock objects. Once a thread has acquired a "
"lock, subsequent attempts to acquire it block, until it is released; any "
"thread may release it."
msgstr ""
"實作原始鎖物件的類別。一旦執行緒獲得了鎖,後續再嘗試獲得它就會被阻塞,直到鎖"
"被釋放;任何執行緒都可以去釋放它。"

#: ../../library/threading.rst:537
msgid ""
"``Lock`` is now a class. In earlier Pythons, ``Lock`` was a factory function "
"which returned an instance of the underlying private lock type."
msgstr ""
"``Lock`` 現在是一個類別。在早期的 Python 中,``Lock`` 是一個會回傳底層私有鎖"
"型別實例的工廠函式。"

#: ../../library/threading.rst:545 ../../library/threading.rst:636
msgid "Acquire a lock, blocking or non-blocking."
msgstr ""
msgstr "阻塞或非阻塞地取得鎖。"

#: ../../library/threading.rst:547
msgid ""
"When invoked with the *blocking* argument set to ``True`` (the default), "
"block until the lock is unlocked, then set it to locked and return ``True``."
msgstr ""
"當以 *blocking* 引數設為 ``True``\\ (預設值)來調用,將會阻塞直到鎖被解鎖,"
"然後將其設為鎖定並回傳 ``True``。"

#: ../../library/threading.rst:550
msgid ""
"When invoked with the *blocking* argument set to ``False``, do not block. If "
"a call with *blocking* set to ``True`` would block, return ``False`` "
"immediately; otherwise, set the lock to locked and return ``True``."
msgstr ""
"當以 *blocking* 引數設為 ``False`` 調用則不會阻塞。如果 *blocking* 設定為 "
"``True`` 的呼叫會阻塞,則立即回傳 ``False``;否則將鎖設為鎖定並回傳 "
"``True``。"

#: ../../library/threading.rst:554
msgid ""
Expand All @@ -751,48 +774,55 @@ msgid ""
"specifies an unbounded wait. It is forbidden to specify a *timeout* when "
"*blocking* is ``False``."
msgstr ""
"當使用設定為正值的浮點 *timeout* 引數進行調用,只要持續無法取得鎖,最多會阻"
"塞 *timeout* 指定的秒數。``-1`` 的 *timeout* 引數代表指定為不會停止的等待。"
"當 *blocking* 為 ``False`` 時禁止指定 *timeout*。"

#: ../../library/threading.rst:560
msgid ""
"The return value is ``True`` if the lock is acquired successfully, ``False`` "
"if not (for example if the *timeout* expired)."
msgstr ""
"如果成功取得鎖,則回傳值為 ``True``,否則回傳值為 ``False``\\ (例如像是 "
"*timeout* 已逾期)。"

#: ../../library/threading.rst:563 ../../library/threading.rst:674
#: ../../library/threading.rst:921
msgid "The *timeout* parameter is new."
msgstr ""
msgstr "新的 *timeout* 參數。"

#: ../../library/threading.rst:566
msgid ""
"Lock acquisition can now be interrupted by signals on POSIX if the "
"underlying threading implementation supports it."
msgstr ""
msgstr "如果底層執行緒實作支援的話,鎖的獲取現在可以被 POSIX 上的訊號中斷。"

#: ../../library/threading.rst:573
msgid ""
"Release a lock. This can be called from any thread, not only the thread "
"which has acquired the lock."
msgstr ""
msgstr "釋放鎖。這可以從任何執行緒呼叫,而不是只有獲得鎖的執行緒。"

#: ../../library/threading.rst:576
msgid ""
"When the lock is locked, reset it to unlocked, and return. If any other "
"threads are blocked waiting for the lock to become unlocked, allow exactly "
"one of them to proceed."
msgstr ""
"當鎖被鎖定時,將其重置為未鎖定然後回傳。如果任何其他執行緒在等待鎖被解鎖時被"
"阻塞,只允許其中一個執行緒繼續進行。"

#: ../../library/threading.rst:580
msgid "When invoked on an unlocked lock, a :exc:`RuntimeError` is raised."
msgstr ""
msgstr "當在未鎖定的鎖上調用時,會引發 :exc:`RuntimeError`"

#: ../../library/threading.rst:582 ../../library/threading.rst:690
msgid "There is no return value."
msgstr ""
msgstr "沒有回傳值。"

#: ../../library/threading.rst:586
msgid "Return ``True`` if the lock is acquired."
msgstr ""
msgstr "如果有取得了鎖,則回傳 ``True``。"

#: ../../library/threading.rst:593
msgid "RLock Objects"
Expand All @@ -806,12 +836,18 @@ msgid ""
"state used by primitive locks. In the locked state, some thread owns the "
"lock; in the unlocked state, no thread owns it."
msgstr ""
"可重入鎖 (reentrant lock) 是一種同步原語,同一執行緒可以多次取得它。在內部,"
"除了原始鎖使用的鎖定/未鎖定狀態之外,它還使用「所屬執行緒 (owning thread)」和"
"「遞迴等級 (recursion level)」的概念。在鎖定狀態下,某個執行緒會擁有鎖;在未"
"鎖定狀態下則沒有執行緒擁有它。"

#: ../../library/threading.rst:601
msgid ""
"Threads call a lock's :meth:`~RLock.acquire` method to lock it, and its :"
"meth:`~Lock.release` method to unlock it."
msgstr ""
"執行緒呼叫鎖的 :meth:`~RLock.acquire` 方法來鎖定它,並呼叫它的 :meth:`~Lock."
"release` 方法來解鎖它。"

#: ../../library/threading.rst:606
msgid ""
Expand All @@ -820,6 +856,9 @@ msgid ""
"meth:`~RLock.acquire` and :meth:`~RLock.release` to handle acquiring and "
"releasing the lock for a block of code."
msgstr ""
"可重入鎖支援\\ :ref:`情境管理協定<with-locks>`,因此建議使用 :keyword:`with` "
"而不是手動呼叫 :meth:`~RLock.acquire` 和 :meth:`~RLock.release` 來對程式碼區"
"塊處理鎖的獲得和釋放。"

#: ../../library/threading.rst:611
msgid ""
Expand All @@ -829,6 +868,10 @@ msgid ""
"pair) resets the lock to an unlocked state and allows another thread blocked "
"in :meth:`~RLock.acquire` to proceed."
msgstr ""
"RLock 的 :meth:`~RLock.acquire`/:meth:`~RLock.release` 呼叫成對組合可以嵌套使"
"用,這與 Lock 的 :meth:`~Lock.acquire`/:meth:`~Lock.release` 不同。只有最後一"
"個 :meth:`~RLock.release`\\ (最外面一對的 :meth:`~Lock.release`)會將鎖重置"
"為未鎖定狀態,並允許在 :meth:`~RLock.acquire` 中阻塞的另一個執行緒繼續進行。"

#: ../../library/threading.rst:617
msgid ""
Expand All @@ -837,6 +880,9 @@ msgid ""
"Failing to call release as many times the lock has been acquired can lead to "
"deadlock."
msgstr ""
":meth:`~RLock.acquire`/:meth:`~RLock.release` 必須成對使用:每次獲得都必須在"
"已獲得鎖的執行緒中有一個釋放。如果鎖釋放的次數不能和獲取的次數一樣的話,可能"
"會導致死鎖 (deadlock)。"

#: ../../library/threading.rst:624
msgid ""
Expand All @@ -845,38 +891,47 @@ msgid ""
"reentrant lock, the same thread may acquire it again without blocking; the "
"thread must release it once for each time it has acquired it."
msgstr ""
"此類別實作了可重入鎖物件。可重入鎖必須由獲得它的執行緒釋放。一旦一個執行緒獲"
"得了可重入鎖,同一個執行緒可以再次獲得它而不會阻塞;執行緒每次獲得它也都必須"
"釋放它一次。"

#: ../../library/threading.rst:629
msgid ""
"Note that ``RLock`` is actually a factory function which returns an instance "
"of the most efficient version of the concrete RLock class that is supported "
"by the platform."
msgstr ""
"請注意,``RLock`` 實際上是一個工廠函式,它會回傳平台有支援的特定 RLock 類別的"
"最高效率版本的實例。"

#: ../../library/threading.rst:640
msgid ":ref:`Using RLock as a context manager <with-locks>`"
msgstr ""
msgstr ":ref:`將 RLock 用作為情境管理器 <with-locks>`"

#: ../../library/threading.rst:641
msgid ""
"Recommended over manual :meth:`!acquire` and :meth:`release` calls whenever "
"practical."
msgstr ""
"若是使用場景合理,和手動呼叫 :meth:`!acquire` 和 :meth:`release` 相比,會是更"
"為推薦的使用方式。"

#: ../../library/threading.rst:645
msgid ""
"When invoked with the *blocking* argument set to ``True`` (the default):"
msgstr ""
msgstr "當以 *blocking* 引數設為 ``True``\\ (預設值)來調用:"

#: ../../library/threading.rst:647 ../../library/threading.rst:659
msgid "If no thread owns the lock, acquire the lock and return immediately."
msgstr ""
msgstr "如果沒有執行緒擁有鎖,則獲得鎖並立即回傳。"

#: ../../library/threading.rst:649
msgid ""
"If another thread owns the lock, block until we are able to acquire lock, or "
"*timeout*, if set to a positive float value."
msgstr ""
"如果另一個執行緒擁有鎖,則阻塞直到能夠取得鎖,或者達到 *timeout*\\ (如果設定"
"為正浮點值)。"

#: ../../library/threading.rst:652
msgid ""
Expand All @@ -885,34 +940,41 @@ msgid ""
"RLock`; :class:`Lock` handles this case the same as the previous, blocking "
"until the lock can be acquired."
msgstr ""
"如果同一個執行緒擁有鎖,則再次取得鎖,並立即回傳。這就是 :class:`Lock` 和 :"
"class:`!RLock` 之間的差別;:class:`Lock` 處理方式與上一種情況相同,會阻塞直到"
"能夠取得鎖。"

#: ../../library/threading.rst:657
msgid "When invoked with the *blocking* argument set to ``False``:"
msgstr ""
msgstr "當以 *blocking* 引數設為 ``False`` 來調用:"

#: ../../library/threading.rst:661
msgid "If another thread owns the lock, return immediately."
msgstr ""
msgstr "如果另一個執行緒擁有該鎖,則立即回傳。"

#: ../../library/threading.rst:663
msgid ""
"If the same thread owns the lock, acquire the lock again and return "
"immediately."
msgstr ""
msgstr "如果同一個執行緒擁有鎖,則再次取得鎖並立即回傳。"

#: ../../library/threading.rst:666
msgid ""
"In all cases, if the thread was able to acquire the lock, return ``True``. "
"If the thread was unable to acquire the lock (i.e. if not blocking or the "
"timeout was reached) return ``False``."
msgstr ""
"在所有情況下,如果執行緒能夠取得鎖則回傳 ``True``。如果執行緒無法取得鎖(即沒"
"有阻塞或已達超時限制)則回傳 ``False``。"

#: ../../library/threading.rst:670
msgid ""
"If called multiple times, failing to call :meth:`~RLock.release` as many "
"times may lead to deadlock. Consider using :class:`!RLock` as a context "
"manager rather than calling acquire/release directly."
msgstr ""
"如果多次呼叫,又未能呼叫相同次數的 :meth:`~RLock.release`,則可能會導致死鎖。"
"考慮將 :class:`!RLock` 作為情境管理器使用,而不是直接呼叫 acquire/release。"

#: ../../library/threading.rst:680
msgid ""
Expand All @@ -922,13 +984,18 @@ msgid ""
"exactly one of them to proceed. If after the decrement the recursion level "
"is still nonzero, the lock remains locked and owned by the calling thread."
msgstr ""
"釋放鎖並減少遞迴等級。如果被減至零,則將鎖重置為未鎖定(不屬於任何執行緒),"
"並且如果任何其他執行緒被阻塞以等待鎖變成未鎖定狀態,則僅允許其中一個執行緒繼"
"續進行。如果遞減後遞迴等級仍然非零,則鎖會保持鎖定並由呼叫它的執行緒所擁有。"

#: ../../library/threading.rst:686
msgid ""
"Only call this method when the calling thread owns the lock. A :exc:"
"`RuntimeError` is raised if this method is called when the lock is not "
"acquired."
msgstr ""
"僅當呼叫的執行緒擁有鎖時才能呼叫此方法。如果在未取得鎖時呼叫此方法則會引發 :"
"exc:`RuntimeError`。"

#: ../../library/threading.rst:696
msgid "Condition Objects"
Expand Down

0 comments on commit 7949b02

Please sign in to comment.