@@ -673,7 +673,7 @@ msgstr ""
673
673
674
674
#: ../../library/threading.rst:503
675
675
msgid "Lock Objects"
676
- msgstr ""
676
+ msgstr "Lock 物件 "
677
677
678
678
#: ../../library/threading.rst:505
679
679
msgid ""
@@ -682,6 +682,9 @@ msgid ""
682
682
"synchronization primitive available, implemented directly by the :mod:"
683
683
"`_thread` extension module."
684
684
msgstr ""
685
+ "原始鎖 (primitive lock) 是一種同步原語 (synchronization primitive),在鎖定時"
686
+ "不屬於特定執行緒。在 Python 中,它是目前可用的最低階同步原語,直接由 :mod:"
687
+ "`_thread` 擴充模組實作。"
685
688
686
689
#: ../../library/threading.rst:510
687
690
msgid ""
@@ -696,10 +699,18 @@ msgid ""
696
699
"state to unlocked and returns immediately. If an attempt is made to release "
697
700
"an unlocked lock, a :exc:`RuntimeError` will be raised."
698
701
msgstr ""
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`。"
699
710
700
711
#: ../../library/threading.rst:521
701
712
msgid "Locks also support the :ref:`context management protocol <with-locks>`."
702
- msgstr ""
713
+ msgstr "鎖也支援 \\ :ref:`情境管理協定 <with-locks>`。 "
703
714
704
715
#: ../../library/threading.rst:523
705
716
msgid ""
@@ -708,40 +719,52 @@ msgid ""
708
719
"release` call resets the state to unlocked; which one of the waiting threads "
709
720
"proceeds is not defined, and may vary across implementations."
710
721
msgstr ""
722
+ "當多個執行緒阻塞在 :meth:`~Lock.acquire` 中等待狀態轉變為未鎖定,此時若呼叫 :"
723
+ "meth:`~Lock.release` 將狀態重置為未鎖定,則只會有一個執行緒繼續進行;哪一個等"
724
+ "待執行緒會繼續進行是未定義的,並且可能因實作而異。"
711
725
712
726
#: ../../library/threading.rst:528
713
727
msgid "All methods are executed atomically."
714
- msgstr ""
728
+ msgstr "所有方法均以最小不可分割的操作方式 (atomically) 執行。 "
715
729
716
730
#: ../../library/threading.rst:533
717
731
msgid ""
718
732
"The class implementing primitive lock objects. Once a thread has acquired a "
719
733
"lock, subsequent attempts to acquire it block, until it is released; any "
720
734
"thread may release it."
721
735
msgstr ""
736
+ "實作原始鎖物件的類別。一旦執行緒獲得了鎖,後續再嘗試獲得它就會被阻塞,直到鎖"
737
+ "被釋放;任何執行緒都可以去釋放它。"
722
738
723
739
#: ../../library/threading.rst:537
724
740
msgid ""
725
741
"``Lock`` is now a class. In earlier Pythons, ``Lock`` was a factory function "
726
742
"which returned an instance of the underlying private lock type."
727
743
msgstr ""
744
+ "``Lock`` 現在是一個類別。在早期的 Python 中,``Lock`` 是一個會回傳底層私有鎖"
745
+ "型別實例的工廠函式。"
728
746
729
747
#: ../../library/threading.rst:545 ../../library/threading.rst:636
730
748
msgid "Acquire a lock, blocking or non-blocking."
731
- msgstr ""
749
+ msgstr "阻塞或非阻塞地取得鎖。 "
732
750
733
751
#: ../../library/threading.rst:547
734
752
msgid ""
735
753
"When invoked with the *blocking* argument set to ``True`` (the default), "
736
754
"block until the lock is unlocked, then set it to locked and return ``True``."
737
755
msgstr ""
756
+ "當以 *blocking* 引數設為 ``True``\\ (預設值)來調用,將會阻塞直到鎖被解鎖,"
757
+ "然後將其設為鎖定並回傳 ``True``。"
738
758
739
759
#: ../../library/threading.rst:550
740
760
msgid ""
741
761
"When invoked with the *blocking* argument set to ``False``, do not block. If "
742
762
"a call with *blocking* set to ``True`` would block, return ``False`` "
743
763
"immediately; otherwise, set the lock to locked and return ``True``."
744
764
msgstr ""
765
+ "當以 *blocking* 引數設為 ``False`` 調用則不會阻塞。如果 *blocking* 設定為 "
766
+ "``True`` 的呼叫會阻塞,則立即回傳 ``False``;否則將鎖設為鎖定並回傳 "
767
+ "``True``。"
745
768
746
769
#: ../../library/threading.rst:554
747
770
msgid ""
@@ -751,48 +774,55 @@ msgid ""
751
774
"specifies an unbounded wait. It is forbidden to specify a *timeout* when "
752
775
"*blocking* is ``False``."
753
776
msgstr ""
777
+ "當使用設定為正值的浮點 *timeout* 引數進行調用,只要持續無法取得鎖,最多會阻"
778
+ "塞 *timeout* 指定的秒數。``-1`` 的 *timeout* 引數代表指定為不會停止的等待。"
779
+ "當 *blocking* 為 ``False`` 時禁止指定 *timeout*。"
754
780
755
781
#: ../../library/threading.rst:560
756
782
msgid ""
757
783
"The return value is ``True`` if the lock is acquired successfully, ``False`` "
758
784
"if not (for example if the *timeout* expired)."
759
785
msgstr ""
786
+ "如果成功取得鎖,則回傳值為 ``True``,否則回傳值為 ``False``\\ (例如像是 "
787
+ "*timeout* 已逾期)。"
760
788
761
789
#: ../../library/threading.rst:563 ../../library/threading.rst:674
762
790
#: ../../library/threading.rst:921
763
791
msgid "The *timeout* parameter is new."
764
- msgstr ""
792
+ msgstr "新的 *timeout* 參數。 "
765
793
766
794
#: ../../library/threading.rst:566
767
795
msgid ""
768
796
"Lock acquisition can now be interrupted by signals on POSIX if the "
769
797
"underlying threading implementation supports it."
770
- msgstr ""
798
+ msgstr "如果底層執行緒實作支援的話,鎖的獲取現在可以被 POSIX 上的訊號中斷。 "
771
799
772
800
#: ../../library/threading.rst:573
773
801
msgid ""
774
802
"Release a lock. This can be called from any thread, not only the thread "
775
803
"which has acquired the lock."
776
- msgstr ""
804
+ msgstr "釋放鎖。這可以從任何執行緒呼叫,而不是只有獲得鎖的執行緒。 "
777
805
778
806
#: ../../library/threading.rst:576
779
807
msgid ""
780
808
"When the lock is locked, reset it to unlocked, and return. If any other "
781
809
"threads are blocked waiting for the lock to become unlocked, allow exactly "
782
810
"one of them to proceed."
783
811
msgstr ""
812
+ "當鎖被鎖定時,將其重置為未鎖定然後回傳。如果任何其他執行緒在等待鎖被解鎖時被"
813
+ "阻塞,只允許其中一個執行緒繼續進行。"
784
814
785
815
#: ../../library/threading.rst:580
786
816
msgid "When invoked on an unlocked lock, a :exc:`RuntimeError` is raised."
787
- msgstr ""
817
+ msgstr "當在未鎖定的鎖上調用時,會引發 :exc:`RuntimeError` "
788
818
789
819
#: ../../library/threading.rst:582 ../../library/threading.rst:690
790
820
msgid "There is no return value."
791
- msgstr ""
821
+ msgstr "沒有回傳值。 "
792
822
793
823
#: ../../library/threading.rst:586
794
824
msgid "Return ``True`` if the lock is acquired."
795
- msgstr ""
825
+ msgstr "如果有取得了鎖,則回傳 ``True``。 "
796
826
797
827
#: ../../library/threading.rst:593
798
828
msgid "RLock Objects"
@@ -806,12 +836,18 @@ msgid ""
806
836
"state used by primitive locks. In the locked state, some thread owns the "
807
837
"lock; in the unlocked state, no thread owns it."
808
838
msgstr ""
839
+ "可重入鎖 (reentrant lock) 是一種同步原語,同一執行緒可以多次取得它。在內部,"
840
+ "除了原始鎖使用的鎖定/未鎖定狀態之外,它還使用「所屬執行緒 (owning thread)」和"
841
+ "「遞迴等級 (recursion level)」的概念。在鎖定狀態下,某個執行緒會擁有鎖;在未"
842
+ "鎖定狀態下則沒有執行緒擁有它。"
809
843
810
844
#: ../../library/threading.rst:601
811
845
msgid ""
812
846
"Threads call a lock's :meth:`~RLock.acquire` method to lock it, and its :"
813
847
"meth:`~Lock.release` method to unlock it."
814
848
msgstr ""
849
+ "執行緒呼叫鎖的 :meth:`~RLock.acquire` 方法來鎖定它,並呼叫它的 :meth:`~Lock."
850
+ "release` 方法來解鎖它。"
815
851
816
852
#: ../../library/threading.rst:606
817
853
msgid ""
@@ -820,6 +856,9 @@ msgid ""
820
856
"meth:`~RLock.acquire` and :meth:`~RLock.release` to handle acquiring and "
821
857
"releasing the lock for a block of code."
822
858
msgstr ""
859
+ "可重入鎖支援\\ :ref:`情境管理協定<with-locks>`,因此建議使用 :keyword:`with` "
860
+ "而不是手動呼叫 :meth:`~RLock.acquire` 和 :meth:`~RLock.release` 來對程式碼區"
861
+ "塊處理鎖的獲得和釋放。"
823
862
824
863
#: ../../library/threading.rst:611
825
864
msgid ""
@@ -829,6 +868,10 @@ msgid ""
829
868
"pair) resets the lock to an unlocked state and allows another thread blocked "
830
869
"in :meth:`~RLock.acquire` to proceed."
831
870
msgstr ""
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` 中阻塞的另一個執行緒繼續進行。"
832
875
833
876
#: ../../library/threading.rst:617
834
877
msgid ""
@@ -837,6 +880,9 @@ msgid ""
837
880
"Failing to call release as many times the lock has been acquired can lead to "
838
881
"deadlock."
839
882
msgstr ""
883
+ ":meth:`~RLock.acquire`/:meth:`~RLock.release` 必須成對使用:每次獲得都必須在"
884
+ "已獲得鎖的執行緒中有一個釋放。如果鎖釋放的次數不能和獲取的次數一樣的話,可能"
885
+ "會導致死鎖 (deadlock)。"
840
886
841
887
#: ../../library/threading.rst:624
842
888
msgid ""
@@ -845,38 +891,47 @@ msgid ""
845
891
"reentrant lock, the same thread may acquire it again without blocking; the "
846
892
"thread must release it once for each time it has acquired it."
847
893
msgstr ""
894
+ "此類別實作了可重入鎖物件。可重入鎖必須由獲得它的執行緒釋放。一旦一個執行緒獲"
895
+ "得了可重入鎖,同一個執行緒可以再次獲得它而不會阻塞;執行緒每次獲得它也都必須"
896
+ "釋放它一次。"
848
897
849
898
#: ../../library/threading.rst:629
850
899
msgid ""
851
900
"Note that ``RLock`` is actually a factory function which returns an instance "
852
901
"of the most efficient version of the concrete RLock class that is supported "
853
902
"by the platform."
854
903
msgstr ""
904
+ "請注意,``RLock`` 實際上是一個工廠函式,它會回傳平台有支援的特定 RLock 類別的"
905
+ "最高效率版本的實例。"
855
906
856
907
#: ../../library/threading.rst:640
857
908
msgid ":ref:`Using RLock as a context manager <with-locks>`"
858
- msgstr ""
909
+ msgstr ":ref:`將 RLock 用作為情境管理器 <with-locks>` "
859
910
860
911
#: ../../library/threading.rst:641
861
912
msgid ""
862
913
"Recommended over manual :meth:`!acquire` and :meth:`release` calls whenever "
863
914
"practical."
864
915
msgstr ""
916
+ "若是使用場景合理,和手動呼叫 :meth:`!acquire` 和 :meth:`release` 相比,會是更"
917
+ "為推薦的使用方式。"
865
918
866
919
#: ../../library/threading.rst:645
867
920
msgid ""
868
921
"When invoked with the *blocking* argument set to ``True`` (the default):"
869
- msgstr ""
922
+ msgstr "當以 *blocking* 引數設為 ``True`` \\ (預設值)來調用: "
870
923
871
924
#: ../../library/threading.rst:647 ../../library/threading.rst:659
872
925
msgid "If no thread owns the lock, acquire the lock and return immediately."
873
- msgstr ""
926
+ msgstr "如果沒有執行緒擁有鎖,則獲得鎖並立即回傳。 "
874
927
875
928
#: ../../library/threading.rst:649
876
929
msgid ""
877
930
"If another thread owns the lock, block until we are able to acquire lock, or "
878
931
"*timeout*, if set to a positive float value."
879
932
msgstr ""
933
+ "如果另一個執行緒擁有鎖,則阻塞直到能夠取得鎖,或者達到 *timeout*\\ (如果設定"
934
+ "為正浮點值)。"
880
935
881
936
#: ../../library/threading.rst:652
882
937
msgid ""
@@ -885,34 +940,41 @@ msgid ""
885
940
"RLock`; :class:`Lock` handles this case the same as the previous, blocking "
886
941
"until the lock can be acquired."
887
942
msgstr ""
943
+ "如果同一個執行緒擁有鎖,則再次取得鎖,並立即回傳。這就是 :class:`Lock` 和 :"
944
+ "class:`!RLock` 之間的差別;:class:`Lock` 處理方式與上一種情況相同,會阻塞直到"
945
+ "能夠取得鎖。"
888
946
889
947
#: ../../library/threading.rst:657
890
948
msgid "When invoked with the *blocking* argument set to ``False``:"
891
- msgstr ""
949
+ msgstr "當以 *blocking* 引數設為 ``False`` 來調用: "
892
950
893
951
#: ../../library/threading.rst:661
894
952
msgid "If another thread owns the lock, return immediately."
895
- msgstr ""
953
+ msgstr "如果另一個執行緒擁有該鎖,則立即回傳。 "
896
954
897
955
#: ../../library/threading.rst:663
898
956
msgid ""
899
957
"If the same thread owns the lock, acquire the lock again and return "
900
958
"immediately."
901
- msgstr ""
959
+ msgstr "如果同一個執行緒擁有鎖,則再次取得鎖並立即回傳。 "
902
960
903
961
#: ../../library/threading.rst:666
904
962
msgid ""
905
963
"In all cases, if the thread was able to acquire the lock, return ``True``. "
906
964
"If the thread was unable to acquire the lock (i.e. if not blocking or the "
907
965
"timeout was reached) return ``False``."
908
966
msgstr ""
967
+ "在所有情況下,如果執行緒能夠取得鎖則回傳 ``True``。如果執行緒無法取得鎖(即沒"
968
+ "有阻塞或已達超時限制)則回傳 ``False``。"
909
969
910
970
#: ../../library/threading.rst:670
911
971
msgid ""
912
972
"If called multiple times, failing to call :meth:`~RLock.release` as many "
913
973
"times may lead to deadlock. Consider using :class:`!RLock` as a context "
914
974
"manager rather than calling acquire/release directly."
915
975
msgstr ""
976
+ "如果多次呼叫,又未能呼叫相同次數的 :meth:`~RLock.release`,則可能會導致死鎖。"
977
+ "考慮將 :class:`!RLock` 作為情境管理器使用,而不是直接呼叫 acquire/release。"
916
978
917
979
#: ../../library/threading.rst:680
918
980
msgid ""
@@ -922,13 +984,18 @@ msgid ""
922
984
"exactly one of them to proceed. If after the decrement the recursion level "
923
985
"is still nonzero, the lock remains locked and owned by the calling thread."
924
986
msgstr ""
987
+ "釋放鎖並減少遞迴等級。如果被減至零,則將鎖重置為未鎖定(不屬於任何執行緒),"
988
+ "並且如果任何其他執行緒被阻塞以等待鎖變成未鎖定狀態,則僅允許其中一個執行緒繼"
989
+ "續進行。如果遞減後遞迴等級仍然非零,則鎖會保持鎖定並由呼叫它的執行緒所擁有。"
925
990
926
991
#: ../../library/threading.rst:686
927
992
msgid ""
928
993
"Only call this method when the calling thread owns the lock. A :exc:"
929
994
"`RuntimeError` is raised if this method is called when the lock is not "
930
995
"acquired."
931
996
msgstr ""
997
+ "僅當呼叫的執行緒擁有鎖時才能呼叫此方法。如果在未取得鎖時呼叫此方法則會引發 :"
998
+ "exc:`RuntimeError`。"
932
999
933
1000
#: ../../library/threading.rst:696
934
1001
msgid "Condition Objects"
0 commit comments