Skip to content

Commit ad888b0

Browse files
committed
feat: to rst:596
1 parent c63067c commit ad888b0

File tree

1 file changed

+52
-13
lines changed

1 file changed

+52
-13
lines changed

library/weakref.po

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgstr ""
88
"Project-Id-Version: Python 3.12\n"
99
"Report-Msgid-Bugs-To: \n"
1010
"POT-Creation-Date: 2023-10-11 17:13+0000\n"
11-
"PO-Revision-Date: 2024-05-14 21:09+0800\n"
11+
"PO-Revision-Date: 2024-05-17 00:33+0800\n"
1212
"Last-Translator: Adrian Liaw <[email protected]>\n"
1313
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1414
"tw)\n"
@@ -111,7 +111,7 @@ msgid ""
111111
"object is collected."
112112
msgstr ""
113113
":class:`finalize` 提供了一種直接的方法來註冊在物件被垃圾回收時呼叫的清理函"
114-
"式。這比在原始弱參照上設定回呼函式更容易使用,因為模組在物件被收集前會自動確"
114+
"式。這比在原始弱參照上設定回呼函式更容易使用,因為模組在物件被回收前會自動確"
115115
"保最終化函式 (finalizer) 保持存活。"
116116

117117
#: ../../library/weakref.rst:63
@@ -410,7 +410,7 @@ msgid ""
410410
"finalizer returns the result of evaluating ``func(*arg, **kwargs)``, whereas "
411411
"calling a dead finalizer returns :const:`None`."
412412
msgstr ""
413-
"最終化函式在被呼叫(明確呼叫或在垃圾收集時)之前被視為\\ *存活*,之後它就會"
413+
"最終化函式在被呼叫(明確呼叫或在垃圾回收時)之前被視為\\ *存活*,之後它就會"
414414
"\\ *死亡*。呼叫存活的最終化函式會回傳 ``func(*arg, **kwargs)`` 的計算結果,而"
415415
"呼叫死亡的最終化函式會回傳 :const:`None`。"
416416

@@ -431,7 +431,7 @@ msgid ""
431431
"attr:`atexit` attribute has been set to false. They are called in reverse "
432432
"order of creation."
433433
msgstr ""
434-
"當程式退出時,除非該最終化函式的 :attr:`atexit` 屬性已被設定為 false,否則每"
434+
"當程式結束時,除非該最終化函式的 :attr:`atexit` 屬性已被設定為 false,否則每"
435435
"個存活的最終化函式會被呼叫。它們以與建立相反的順序被呼叫。"
436436

437437
#: ../../library/weakref.rst:290
@@ -477,7 +477,7 @@ msgid ""
477477
"exits, it calls all remaining live finalizers for which :attr:`.atexit` is "
478478
"true. They are called in reverse order of creation."
479479
msgstr ""
480-
"一個可寫的布林屬性,預設為 true。當程式退出時,它會呼叫 :attr:`.atexit` 為 "
480+
"一個可寫的布林屬性,預設為 true。當程式結束時,它會呼叫 :attr:`.atexit` 為 "
481481
"true 的所有剩餘且仍存活的最終化函式。它們以與建立相反的順序被呼叫。"
482482

483483
#: ../../library/weakref.rst:324
@@ -523,27 +523,31 @@ msgstr "此功能的提案和理由,包括早期實作的連結以及其他語
523523

524524
#: ../../library/weakref.rst:364
525525
msgid "Weak Reference Objects"
526-
msgstr ""
526+
msgstr "弱參照物件"
527527

528528
#: ../../library/weakref.rst:366
529529
msgid ""
530530
"Weak reference objects have no methods and no attributes besides :attr:`ref."
531531
"__callback__`. A weak reference object allows the referent to be obtained, "
532532
"if it still exists, by calling it:"
533533
msgstr ""
534+
"弱參照物件除了 :attr:`ref.__callback__` 之外沒有任何方法和屬性。弱參照物件允"
535+
"許透過呼叫來獲取參照目標(如果它仍然存在):"
534536

535537
#: ../../library/weakref.rst:380
536538
msgid ""
537539
"If the referent no longer exists, calling the reference object returns :"
538540
"const:`None`:"
539-
msgstr ""
541+
msgstr "如果參照目標不再存活,則呼叫參照物件將回傳 :const:`None`:"
540542

541543
#: ../../library/weakref.rst:387
542544
msgid ""
543545
"Testing that a weak reference object is still live should be done using the "
544546
"expression ``ref() is not None``. Normally, application code that needs to "
545547
"use a reference object should follow this pattern::"
546548
msgstr ""
549+
"應該使用運算式 ``ref() is not None`` 來測試弱參照物件是否仍然存活。需要使用參"
550+
"照物件的應用程式程式碼通常應遵循以下模式: ::"
547551

548552
#: ../../library/weakref.rst:400
549553
msgid ""
@@ -552,6 +556,9 @@ msgid ""
552556
"invalidated before the weak reference is called; the idiom shown above is "
553557
"safe in threaded applications as well as single-threaded applications."
554558
msgstr ""
559+
"使用對「活性 (liveness)」的單獨測試會在執行緒應用程式中建立競爭條件 (race "
560+
"condition);另一個執行緒可能在弱參照被呼叫之前讓該弱參照失效;上方顯示的慣用"
561+
"作法在執行緒應用程式和單執行緒應用程式中都是安全的。"
555562

556563
#: ../../library/weakref.rst:405
557564
msgid ""
@@ -562,13 +569,19 @@ msgid ""
562569
"reference, but could also be used to insert additional processing on calls "
563570
"to retrieve the referent."
564571
msgstr ""
572+
"可以透過子類別化來建立 :class:`ref` 物件的特殊版本。這在 :class:"
573+
"`WeakValueDictionary` 的實作中被使用,以減少對映中每個條目的記憶體開銷。這對"
574+
"於將附加資訊與參照相關聯最有用,但也可用於在呼叫上插入附加處理以檢索參照目"
575+
"標。"
565576

566577
#: ../../library/weakref.rst:411
567578
msgid ""
568579
"This example shows how a subclass of :class:`ref` can be used to store "
569580
"additional information about an object and affect the value that's returned "
570581
"when the referent is accessed::"
571582
msgstr ""
583+
"這個範例展示如何使用 :class:`ref` 的子類別來儲存有關物件的附加資訊並影響存取"
584+
"參照目標時回傳的值: ::"
572585

573586
#: ../../library/weakref.rst:438
574587
msgid "Example"
@@ -581,66 +594,78 @@ msgid ""
581594
"other data structures without forcing the objects to remain alive, but the "
582595
"objects can still be retrieved by ID if they do."
583596
msgstr ""
597+
"這個簡單的範例展示了應用程式如何使用物件 ID 來檢索它以前見過​​的物件。物件的 "
598+
"ID 之後可以在其他資料結構中使用,而不必強制物件保持存活,但如果這樣做,仍然可"
599+
"以透過 ID 檢索物件。"
584600

585601
#: ../../library/weakref.rst:465
586602
msgid "Finalizer Objects"
587-
msgstr ""
603+
msgstr "最終化函式物件"
588604

589605
#: ../../library/weakref.rst:467
590606
msgid ""
591607
"The main benefit of using :class:`finalize` is that it makes it simple to "
592608
"register a callback without needing to preserve the returned finalizer "
593609
"object. For instance"
594610
msgstr ""
611+
"使用 :class:`finalize` 的最大優點是可以輕鬆註冊回呼,而無需保留回傳的最終化函"
612+
"式物件。例如"
595613

596614
#: ../../library/weakref.rst:481
597615
msgid ""
598616
"The finalizer can be called directly as well. However the finalizer will "
599617
"invoke the callback at most once."
600-
msgstr ""
618+
msgstr "最終化函式也可以直接被呼叫。然而,最終化函式最多會調用回乎一次。"
601619

602620
#: ../../library/weakref.rst:497
603621
msgid ""
604622
"You can unregister a finalizer using its :meth:`~finalize.detach` method. "
605623
"This kills the finalizer and returns the arguments passed to the constructor "
606624
"when it was created."
607625
msgstr ""
626+
"你可以使用最終化函式的 :meth:`~finalize.detach` 方法來取消註冊最終化函式。這"
627+
"會殺死最終化函式並回傳建立建構函式時傳遞給建構函式的引數。"
608628

609629
#: ../../library/weakref.rst:511
610630
msgid ""
611631
"Unless you set the :attr:`~finalize.atexit` attribute to :const:`False`, a "
612632
"finalizer will be called when the program exits if it is still alive. For "
613633
"instance"
614634
msgstr ""
635+
"除非你將 :attr:`~finalize.atexit` 屬性設為 :const:`False`,否則當程式結束時,"
636+
"最終化函式將會被呼叫如果其仍然存在。例如"
615637

616638
#: ../../library/weakref.rst:526
617639
msgid "Comparing finalizers with :meth:`~object.__del__` methods"
618-
msgstr ""
640+
msgstr "最終化函式與 :meth:`~object.__del__` 方法的比較"
619641

620642
#: ../../library/weakref.rst:528
621643
msgid ""
622644
"Suppose we want to create a class whose instances represent temporary "
623645
"directories. The directories should be deleted with their contents when the "
624646
"first of the following events occurs:"
625647
msgstr ""
648+
"假設我們要建立一個類別,其實例代表臨時目錄。當以下任一事件發生時,應刪除目錄"
649+
"及其內容:"
626650

627651
#: ../../library/weakref.rst:532
628652
msgid "the object is garbage collected,"
629-
msgstr ""
653+
msgstr "該物件被垃圾回收,"
630654

631655
#: ../../library/weakref.rst:533
632656
msgid "the object's :meth:`!remove` method is called, or"
633-
msgstr ""
657+
msgstr "該物件的 :meth:`!remove` 方法被呼叫,或者"
634658

635659
#: ../../library/weakref.rst:534
636660
msgid "the program exits."
637-
msgstr ""
661+
msgstr "程式結束。"
638662

639663
#: ../../library/weakref.rst:536
640664
msgid ""
641665
"We might try to implement the class using a :meth:`~object.__del__` method "
642666
"as follows::"
643667
msgstr ""
668+
"我們可以用以下的方式來嘗試使用 :meth:`~object.__del__` 方法實作該類別: ::"
644669

645670
#: ../../library/weakref.rst:555
646671
msgid ""
@@ -649,34 +674,45 @@ msgid ""
649674
"longer forced to :const:`None` during :term:`interpreter shutdown`. So this "
650675
"code should work without any issues on CPython."
651676
msgstr ""
677+
"從 Python 3.4 開始,:meth:`~object.__del__` 方法不再阻止參照循環 (reference "
678+
"cycle) 被垃圾回收,並且在 :term:`interpreter shutdown` 期間不再強制將模組的 "
679+
"globals 設為 :const:`None`。所以這段程式碼在 CPython 上應該可以正常運作。"
652680

653681
#: ../../library/weakref.rst:560
654682
msgid ""
655683
"However, handling of :meth:`~object.__del__` methods is notoriously "
656684
"implementation specific, since it depends on internal details of the "
657685
"interpreter's garbage collector implementation."
658686
msgstr ""
687+
"然而,眾所周知,對 :meth:`~object.__del__` 方法的處理是特地實作的,因為它依賴"
688+
"於直譯器的垃圾回收器實作的內部細節。"
659689

660690
#: ../../library/weakref.rst:564
661691
msgid ""
662692
"A more robust alternative can be to define a finalizer which only references "
663693
"the specific functions and objects that it needs, rather than having access "
664694
"to the full state of the object::"
665695
msgstr ""
696+
"更耐用的替代方案可以是定義一個最終化函式,其僅參照需要的特定函式和物件,而不"
697+
"是存取物件的完整狀態: ::"
666698

667699
#: ../../library/weakref.rst:580
668700
msgid ""
669701
"Defined like this, our finalizer only receives a reference to the details it "
670702
"needs to clean up the directory appropriately. If the object never gets "
671703
"garbage collected the finalizer will still be called at exit."
672704
msgstr ""
705+
"定義如下,我們的最終化函式僅接收對適當清理目錄所需的詳細資訊的參照。如果物件"
706+
"從未被垃圾回收,則最終化函式仍將在結束時被呼叫。"
673707

674708
#: ../../library/weakref.rst:584
675709
msgid ""
676710
"The other advantage of weakref based finalizers is that they can be used to "
677711
"register finalizers for classes where the definition is controlled by a "
678712
"third party, such as running code when a module is unloaded::"
679713
msgstr ""
714+
"基於 weakref 的最終化函式的另一個優點是它們可用於為定義由第三方控制的類別註冊"
715+
"最終化函式,例如在卸載模組時執行程式碼: ::"
680716

681717
#: ../../library/weakref.rst:596
682718
msgid ""
@@ -685,3 +721,6 @@ msgid ""
685721
"at exit. However, in a daemonic thread :func:`atexit.register`, ``try: ... "
686722
"finally: ...`` and ``with: ...`` do not guarantee that cleanup occurs either."
687723
msgstr ""
724+
"如果在程式結束時在常駐的 (daemonic) 執行緒中建立最終化函式物件,則最終化函式"
725+
"有可能在結束時不會被呼叫。然而,在常駐的執行緒中 :func:`atexit.register`、"
726+
"``try: ... finally: ...`` 和 ``with: ...`` 也不保證清理會發生。"

0 commit comments

Comments
 (0)