@@ -8,7 +8,7 @@ msgstr ""
8
8
"Project-Id-Version : Python 3.12\n "
9
9
"Report-Msgid-Bugs-To : \n "
10
10
"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 "
12
12
"Last-Translator : Adrian Liaw <adrianliaw2000@gmail.com>\n "
13
13
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
14
14
"tw)\n "
@@ -111,7 +111,7 @@ msgid ""
111
111
"object is collected."
112
112
msgstr ""
113
113
":class:`finalize` 提供了一種直接的方法來註冊在物件被垃圾回收時呼叫的清理函"
114
- "式。這比在原始弱參照上設定回呼函式更容易使用,因為模組在物件被收集前會自動確 "
114
+ "式。這比在原始弱參照上設定回呼函式更容易使用,因為模組在物件被回收前會自動確 "
115
115
"保最終化函式 (finalizer) 保持存活。"
116
116
117
117
#: ../../library/weakref.rst:63
@@ -410,7 +410,7 @@ msgid ""
410
410
"finalizer returns the result of evaluating ``func(*arg, **kwargs)``, whereas "
411
411
"calling a dead finalizer returns :const:`None`."
412
412
msgstr ""
413
- "最終化函式在被呼叫(明確呼叫或在垃圾收集時 )之前被視為\\ *存活*,之後它就會"
413
+ "最終化函式在被呼叫(明確呼叫或在垃圾回收時 )之前被視為\\ *存活*,之後它就會"
414
414
"\\ *死亡*。呼叫存活的最終化函式會回傳 ``func(*arg, **kwargs)`` 的計算結果,而"
415
415
"呼叫死亡的最終化函式會回傳 :const:`None`。"
416
416
@@ -431,7 +431,7 @@ msgid ""
431
431
"attr:`atexit` attribute has been set to false. They are called in reverse "
432
432
"order of creation."
433
433
msgstr ""
434
- "當程式退出時 ,除非該最終化函式的 :attr:`atexit` 屬性已被設定為 false,否則每"
434
+ "當程式結束時 ,除非該最終化函式的 :attr:`atexit` 屬性已被設定為 false,否則每"
435
435
"個存活的最終化函式會被呼叫。它們以與建立相反的順序被呼叫。"
436
436
437
437
#: ../../library/weakref.rst:290
@@ -477,7 +477,7 @@ msgid ""
477
477
"exits, it calls all remaining live finalizers for which :attr:`.atexit` is "
478
478
"true. They are called in reverse order of creation."
479
479
msgstr ""
480
- "一個可寫的布林屬性,預設為 true。當程式退出時 ,它會呼叫 :attr:`.atexit` 為 "
480
+ "一個可寫的布林屬性,預設為 true。當程式結束時 ,它會呼叫 :attr:`.atexit` 為 "
481
481
"true 的所有剩餘且仍存活的最終化函式。它們以與建立相反的順序被呼叫。"
482
482
483
483
#: ../../library/weakref.rst:324
@@ -523,27 +523,31 @@ msgstr "此功能的提案和理由,包括早期實作的連結以及其他語
523
523
524
524
#: ../../library/weakref.rst:364
525
525
msgid "Weak Reference Objects"
526
- msgstr ""
526
+ msgstr "弱參照物件 "
527
527
528
528
#: ../../library/weakref.rst:366
529
529
msgid ""
530
530
"Weak reference objects have no methods and no attributes besides :attr:`ref."
531
531
"__callback__`. A weak reference object allows the referent to be obtained, "
532
532
"if it still exists, by calling it:"
533
533
msgstr ""
534
+ "弱參照物件除了 :attr:`ref.__callback__` 之外沒有任何方法和屬性。弱參照物件允"
535
+ "許透過呼叫來獲取參照目標(如果它仍然存在):"
534
536
535
537
#: ../../library/weakref.rst:380
536
538
msgid ""
537
539
"If the referent no longer exists, calling the reference object returns :"
538
540
"const:`None`:"
539
- msgstr ""
541
+ msgstr "如果參照目標不再存活,則呼叫參照物件將回傳 :const:`None`: "
540
542
541
543
#: ../../library/weakref.rst:387
542
544
msgid ""
543
545
"Testing that a weak reference object is still live should be done using the "
544
546
"expression ``ref() is not None``. Normally, application code that needs to "
545
547
"use a reference object should follow this pattern::"
546
548
msgstr ""
549
+ "應該使用運算式 ``ref() is not None`` 來測試弱參照物件是否仍然存活。需要使用參"
550
+ "照物件的應用程式程式碼通常應遵循以下模式: ::"
547
551
548
552
#: ../../library/weakref.rst:400
549
553
msgid ""
@@ -552,6 +556,9 @@ msgid ""
552
556
"invalidated before the weak reference is called; the idiom shown above is "
553
557
"safe in threaded applications as well as single-threaded applications."
554
558
msgstr ""
559
+ "使用對「活性 (liveness)」的單獨測試會在執行緒應用程式中建立競爭條件 (race "
560
+ "condition);另一個執行緒可能在弱參照被呼叫之前讓該弱參照失效;上方顯示的慣用"
561
+ "作法在執行緒應用程式和單執行緒應用程式中都是安全的。"
555
562
556
563
#: ../../library/weakref.rst:405
557
564
msgid ""
@@ -562,13 +569,19 @@ msgid ""
562
569
"reference, but could also be used to insert additional processing on calls "
563
570
"to retrieve the referent."
564
571
msgstr ""
572
+ "可以透過子類別化來建立 :class:`ref` 物件的特殊版本。這在 :class:"
573
+ "`WeakValueDictionary` 的實作中被使用,以減少對映中每個條目的記憶體開銷。這對"
574
+ "於將附加資訊與參照相關聯最有用,但也可用於在呼叫上插入附加處理以檢索參照目"
575
+ "標。"
565
576
566
577
#: ../../library/weakref.rst:411
567
578
msgid ""
568
579
"This example shows how a subclass of :class:`ref` can be used to store "
569
580
"additional information about an object and affect the value that's returned "
570
581
"when the referent is accessed::"
571
582
msgstr ""
583
+ "這個範例展示如何使用 :class:`ref` 的子類別來儲存有關物件的附加資訊並影響存取"
584
+ "參照目標時回傳的值: ::"
572
585
573
586
#: ../../library/weakref.rst:438
574
587
msgid "Example"
@@ -581,66 +594,78 @@ msgid ""
581
594
"other data structures without forcing the objects to remain alive, but the "
582
595
"objects can still be retrieved by ID if they do."
583
596
msgstr ""
597
+ "這個簡單的範例展示了應用程式如何使用物件 ID 來檢索它以前見過的物件。物件的 "
598
+ "ID 之後可以在其他資料結構中使用,而不必強制物件保持存活,但如果這樣做,仍然可"
599
+ "以透過 ID 檢索物件。"
584
600
585
601
#: ../../library/weakref.rst:465
586
602
msgid "Finalizer Objects"
587
- msgstr ""
603
+ msgstr "最終化函式物件 "
588
604
589
605
#: ../../library/weakref.rst:467
590
606
msgid ""
591
607
"The main benefit of using :class:`finalize` is that it makes it simple to "
592
608
"register a callback without needing to preserve the returned finalizer "
593
609
"object. For instance"
594
610
msgstr ""
611
+ "使用 :class:`finalize` 的最大優點是可以輕鬆註冊回呼,而無需保留回傳的最終化函"
612
+ "式物件。例如"
595
613
596
614
#: ../../library/weakref.rst:481
597
615
msgid ""
598
616
"The finalizer can be called directly as well. However the finalizer will "
599
617
"invoke the callback at most once."
600
- msgstr ""
618
+ msgstr "最終化函式也可以直接被呼叫。然而,最終化函式最多會調用回乎一次。 "
601
619
602
620
#: ../../library/weakref.rst:497
603
621
msgid ""
604
622
"You can unregister a finalizer using its :meth:`~finalize.detach` method. "
605
623
"This kills the finalizer and returns the arguments passed to the constructor "
606
624
"when it was created."
607
625
msgstr ""
626
+ "你可以使用最終化函式的 :meth:`~finalize.detach` 方法來取消註冊最終化函式。這"
627
+ "會殺死最終化函式並回傳建立建構函式時傳遞給建構函式的引數。"
608
628
609
629
#: ../../library/weakref.rst:511
610
630
msgid ""
611
631
"Unless you set the :attr:`~finalize.atexit` attribute to :const:`False`, a "
612
632
"finalizer will be called when the program exits if it is still alive. For "
613
633
"instance"
614
634
msgstr ""
635
+ "除非你將 :attr:`~finalize.atexit` 屬性設為 :const:`False`,否則當程式結束時,"
636
+ "最終化函式將會被呼叫如果其仍然存在。例如"
615
637
616
638
#: ../../library/weakref.rst:526
617
639
msgid "Comparing finalizers with :meth:`~object.__del__` methods"
618
- msgstr ""
640
+ msgstr "最終化函式與 :meth:`~object.__del__` 方法的比較 "
619
641
620
642
#: ../../library/weakref.rst:528
621
643
msgid ""
622
644
"Suppose we want to create a class whose instances represent temporary "
623
645
"directories. The directories should be deleted with their contents when the "
624
646
"first of the following events occurs:"
625
647
msgstr ""
648
+ "假設我們要建立一個類別,其實例代表臨時目錄。當以下任一事件發生時,應刪除目錄"
649
+ "及其內容:"
626
650
627
651
#: ../../library/weakref.rst:532
628
652
msgid "the object is garbage collected,"
629
- msgstr ""
653
+ msgstr "該物件被垃圾回收, "
630
654
631
655
#: ../../library/weakref.rst:533
632
656
msgid "the object's :meth:`!remove` method is called, or"
633
- msgstr ""
657
+ msgstr "該物件的 :meth:`!remove` 方法被呼叫,或者 "
634
658
635
659
#: ../../library/weakref.rst:534
636
660
msgid "the program exits."
637
- msgstr ""
661
+ msgstr "程式結束。 "
638
662
639
663
#: ../../library/weakref.rst:536
640
664
msgid ""
641
665
"We might try to implement the class using a :meth:`~object.__del__` method "
642
666
"as follows::"
643
667
msgstr ""
668
+ "我們可以用以下的方式來嘗試使用 :meth:`~object.__del__` 方法實作該類別: ::"
644
669
645
670
#: ../../library/weakref.rst:555
646
671
msgid ""
@@ -649,34 +674,45 @@ msgid ""
649
674
"longer forced to :const:`None` during :term:`interpreter shutdown`. So this "
650
675
"code should work without any issues on CPython."
651
676
msgstr ""
677
+ "從 Python 3.4 開始,:meth:`~object.__del__` 方法不再阻止參照循環 (reference "
678
+ "cycle) 被垃圾回收,並且在 :term:`interpreter shutdown` 期間不再強制將模組的 "
679
+ "globals 設為 :const:`None`。所以這段程式碼在 CPython 上應該可以正常運作。"
652
680
653
681
#: ../../library/weakref.rst:560
654
682
msgid ""
655
683
"However, handling of :meth:`~object.__del__` methods is notoriously "
656
684
"implementation specific, since it depends on internal details of the "
657
685
"interpreter's garbage collector implementation."
658
686
msgstr ""
687
+ "然而,眾所周知,對 :meth:`~object.__del__` 方法的處理是特地實作的,因為它依賴"
688
+ "於直譯器的垃圾回收器實作的內部細節。"
659
689
660
690
#: ../../library/weakref.rst:564
661
691
msgid ""
662
692
"A more robust alternative can be to define a finalizer which only references "
663
693
"the specific functions and objects that it needs, rather than having access "
664
694
"to the full state of the object::"
665
695
msgstr ""
696
+ "更耐用的替代方案可以是定義一個最終化函式,其僅參照需要的特定函式和物件,而不"
697
+ "是存取物件的完整狀態: ::"
666
698
667
699
#: ../../library/weakref.rst:580
668
700
msgid ""
669
701
"Defined like this, our finalizer only receives a reference to the details it "
670
702
"needs to clean up the directory appropriately. If the object never gets "
671
703
"garbage collected the finalizer will still be called at exit."
672
704
msgstr ""
705
+ "定義如下,我們的最終化函式僅接收對適當清理目錄所需的詳細資訊的參照。如果物件"
706
+ "從未被垃圾回收,則最終化函式仍將在結束時被呼叫。"
673
707
674
708
#: ../../library/weakref.rst:584
675
709
msgid ""
676
710
"The other advantage of weakref based finalizers is that they can be used to "
677
711
"register finalizers for classes where the definition is controlled by a "
678
712
"third party, such as running code when a module is unloaded::"
679
713
msgstr ""
714
+ "基於 weakref 的最終化函式的另一個優點是它們可用於為定義由第三方控制的類別註冊"
715
+ "最終化函式,例如在卸載模組時執行程式碼: ::"
680
716
681
717
#: ../../library/weakref.rst:596
682
718
msgid ""
@@ -685,3 +721,6 @@ msgid ""
685
721
"at exit. However, in a daemonic thread :func:`atexit.register`, ``try: ... "
686
722
"finally: ...`` and ``with: ...`` do not guarantee that cleanup occurs either."
687
723
msgstr ""
724
+ "如果在程式結束時在常駐的 (daemonic) 執行緒中建立最終化函式物件,則最終化函式"
725
+ "有可能在結束時不會被呼叫。然而,在常駐的執行緒中 :func:`atexit.register`、"
726
+ "``try: ... finally: ...`` 和 ``with: ...`` 也不保證清理會發生。"
0 commit comments