@@ -8,7 +8,7 @@ msgstr ""
8
8
"Project-Id-Version : Python 3.11\n "
9
9
"Report-Msgid-Bugs-To : \n "
10
10
"POT-Creation-Date : 2022-06-10 00:16+0000\n "
11
- "PO-Revision-Date : 2023-08-03 18:11 +0800\n "
11
+ "PO-Revision-Date : 2023-08-12 15:16 +0800\n "
12
12
"
Last-Translator :
Jay <[email protected] >\n "
13
13
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
14
14
"tw)\n "
@@ -240,7 +240,7 @@ msgstr ""
240
240
msgid ""
241
241
"The :mod:`multiprocessing` integrates cross-platform IPC into a higher-level "
242
242
"API."
243
- msgstr ":mod:`multiprocessing` 將跨平台的行程間通訊整合到更高層的 API 中。"
243
+ msgstr ":mod:`multiprocessing` 將跨平台行程間通訊整合到更高層的 API 中。"
244
244
245
245
#: ../../howto/sockets.rst:134
246
246
msgid "Using a Socket"
@@ -519,7 +519,7 @@ msgstr ""
519
519
520
520
#: ../../howto/sockets.rst:302
521
521
msgid "When Sockets Die"
522
- msgstr ""
522
+ msgstr "Sockets 何時銷毀 "
523
523
524
524
#: ../../howto/sockets.rst:304
525
525
msgid ""
@@ -535,10 +535,17 @@ msgid ""
535
535
"automatic recycling of resources. In other words, if you do manage to kill "
536
536
"the thread, your whole process is likely to be screwed up."
537
537
msgstr ""
538
+ "使用阻塞式 socket 最糟糕的地方可能是在另一端突然強制關閉(未執行 ``close``)"
539
+ "的情況下會發生什麼?你的 socket 很可能會處於阻塞狀態。TCP 是一種可靠的協議,"
540
+ "它在放棄連線之前會等待很長很長的時間。如果你正在使用執行緒,整個執行緒基本上"
541
+ "已經無法使用。在這方面,你無法做太多事情。只要你不做一些愚蠢的事情,比如在"
542
+ "執行阻塞式讀取時持有一個鎖,那麼執行緒並不會消耗太多資源。*不要*\\ 試圖終止"
543
+ "執行緒 - 執行緒比行程更有效的部分原因是它們避免了與自動回收資源相關的開銷。換"
544
+ "句話說,如果你確實設法終止了執行緒,整個行程可能會出現問題。"
538
545
539
546
#: ../../howto/sockets.rst:318
540
547
msgid "Non-blocking Sockets"
541
- msgstr ""
548
+ msgstr "非阻塞的 Sockets "
542
549
543
550
#: ../../howto/sockets.rst:320
544
551
msgid ""
@@ -547,6 +554,9 @@ msgid ""
547
554
"calls, in much the same ways. It's just that, if you do it right, your app "
548
555
"will be almost inside-out."
549
556
msgstr ""
557
+ "如果你已經理解了前面的內容,你已經知道了大部分關於使用 sockets 的機制的所需知"
558
+ "識,你仍然會以非常相似的方式使用相同的函式。就這樣而已,如果你做的對,你的程式"
559
+ "就會是近乎完美的。"
550
560
551
561
#: ../../howto/sockets.rst:325
552
562
msgid ""
@@ -557,6 +567,11 @@ msgid ""
557
567
"the exact same idea. You do this after creating the socket, but before using "
558
568
"it. (Actually, if you're nuts, you can switch back and forth.)"
559
569
msgstr ""
570
+ "在 Python 中可以使用 ``socket.setblocking(False)`` 來設定為非阻塞。在 C 的作"
571
+ "法更為複雜(例如,你需要在 BSD 風格的 ``O_NONBLOCK`` 和幾乎沒有區別的 POSIX 風"
572
+ "格的 ``O_NDELAY`` 之間做出選擇,這與 ``TCP_NODELAY`` 完全不同),但基本思想是"
573
+ "一樣的,你要在建立 socket 後但在使用它之前執行此操作。(實際上,如果你願意的"
574
+ "話,你甚至可以來回切換。)"
560
575
561
576
#: ../../howto/sockets.rst:332
562
577
msgid ""
@@ -567,17 +582,24 @@ msgid ""
567
582
"will grow large, buggy and suck CPU. So let's skip the brain-dead solutions "
568
583
"and do it right."
569
584
msgstr ""
585
+ "主要的機制差異在於 ``send``、``recv``、``connect`` 和 ``accept`` 可能在沒有執"
586
+ "行任何操作的情況下就回傳了。你當然有多種選擇。你可以檢查回傳值和錯誤代碼,但"
587
+ "這些操作通常會讓自己抓狂。如果你不相信我,不妨試試看。你的應用程式會變得臃"
588
+ "腫、錯誤百出,並且占用 CPU。所以,讓我們跳過無腦的解決方案,使用正確的方式。"
570
589
571
590
#: ../../howto/sockets.rst:339
572
591
msgid "Use ``select``."
573
- msgstr ""
592
+ msgstr "使用 ``select``。 "
574
593
575
594
#: ../../howto/sockets.rst:341
576
595
msgid ""
577
596
"In C, coding ``select`` is fairly complex. In Python, it's a piece of cake, "
578
597
"but it's close enough to the C version that if you understand ``select`` in "
579
598
"Python, you'll have little trouble with it in C::"
580
599
msgstr ""
600
+ "在 C 中,編寫 ``select`` 是非常複雜的,但在 Python 中,這很簡單,並與 C 的版"
601
+ "本非常類似,如果你理解了 Python 中的 ``select``,在 C 中處理它時也不會有太大"
602
+ "的困難: ::"
581
603
582
604
#: ../../howto/sockets.rst:352
583
605
msgid ""
@@ -589,13 +611,20 @@ msgid ""
589
611
"generally a sensible thing to do - give it a nice long timeout (say a "
590
612
"minute) unless you have good reason to do otherwise."
591
613
msgstr ""
614
+ "你傳遞給 ``select`` 三個列表:第一個列表包含你可能想要嘗試讀取的所有 "
615
+ "sockets;第二個包含所有你可能想要嘗試寫入的 sockets,最後一個(通常為空)包含"
616
+ "你想要檢查錯誤的 sockets。你應該注意,一個 socket 可以同時存在於多個列表中。"
617
+ "``select`` 呼叫是阻塞的,但你可以設置超時。通常這是一個明智的做法 - 除非有"
618
+ "充分的理由,否則給它一個很長的超時(比如一分鐘)。"
592
619
593
620
#: ../../howto/sockets.rst:360
594
621
msgid ""
595
622
"In return, you will get three lists. They contain the sockets that are "
596
623
"actually readable, writable and in error. Each of these lists is a subset "
597
624
"(possibly empty) of the corresponding list you passed in."
598
625
msgstr ""
626
+ "作為回傳,你將獲得三個列表。它們包含實際上可讀取、可寫入和出錯的 sockets。這"
627
+ "些列表中的每一個都是你傳入的相應列表的子集(可能為空)。"
599
628
600
629
#: ../../howto/sockets.rst:364
601
630
msgid ""
@@ -606,6 +635,11 @@ msgid ""
606
635
"nothing. (Actually, any reasonably healthy socket will return as writable - "
607
636
"it just means outbound network buffer space is available.)"
608
637
msgstr ""
638
+ "如果一個 socket 在輸出的可讀列表中,你可以幾乎確定,在這個業務中我們能夠得到"
639
+ "的最接近確定的事情是,對該 socket 的 ``recv`` 呼叫將會回傳一些\\ *內容*。對於可寫"
640
+ "列表,也是同樣的想法。你將能夠發送一些 *內容*。也許不是全部,但\\ *一些內容*\\ 總比"
641
+ "什麼都沒有好。(實際上,任何比較正常的 socket 都會以可寫的方式回傳 - 這只是意味"
642
+ "者「外送網路 (outbound network)」的緩衝空間是可用的。)"
609
643
610
644
#: ../../howto/sockets.rst:371
611
645
msgid ""
@@ -615,6 +649,10 @@ msgid ""
615
649
"it in the potential_writers list. If it shows up in the writable list, you "
616
650
"have a decent chance that it has connected."
617
651
msgstr ""
652
+ "如果你有一個「伺服器端」socket,請將其放在 potential_readers 列表中,如果它在"
653
+ "可讀列表中出現,你的 ``accept`` 呼叫(幾乎可以確定)會成功。如果你建立了一個"
654
+ "新的 socket 去 ``connect`` 到其他地方,請將它放在 potential_writers 列表中,"
655
+ "如果它在可寫列表中出現,那麼他有可能已經連接上了。"
618
656
619
657
#: ../../howto/sockets.rst:377
620
658
msgid ""
@@ -624,6 +662,9 @@ msgid ""
624
662
"problem of determining whether the other end is done, or just busy with "
625
663
"something else."
626
664
msgstr ""
665
+ "實際上,即使是使用阻塞式 socket 的情況下,``select`` 也很方便。這是一種判斷是否"
666
+ "會被阻塞的方法之一 - 當緩衝區中有某些內容時, socket 會回傳為可讀。然而,這"
667
+ "仍然無法解決判斷另一端是否完成,或者只是忙於其他事情的問題。"
627
668
628
669
#: ../../howto/sockets.rst:382
629
670
msgid ""
@@ -633,3 +674,8 @@ msgid ""
633
674
"differently on Windows. In fact, on Windows I usually use threads (which "
634
675
"work very, very well) with my sockets."
635
676
msgstr ""
677
+ "**可移植性警告**:在 Unix 上,``select`` 同時適用於 sockets 和文件。但請不要"
678
+ "在 Windows 上嘗試這麼做,在 Windows 上,``select`` 只適用於 sockets。同時,請"
679
+ "注意,在 C 語言中,許多更進階的 socket 選項在 Windows 上有不同的實現方式。實"
680
+ "際上,在 Windows 上,我通常會使用執行緒(這非常,非常有效)與我的 sockets 一起"
681
+ "使用。"
0 commit comments