Skip to content

Commit a1e5917

Browse files
feat(howto/sockets.po): 翻譯 When Sockets Die 和 Non-blocking Sockets 區塊 (#581)
* feat(howto/sockets.po): 翻譯 When Sockets Die 和 Non-blocking Sockets 區塊 gh-466 * fix(howto/sockets.po): 根據 review 建議更改翻譯內容 gh-466 * fix(howto/sockets.po): 修改 rst 語法 gh-466 * Apply suggestions from code review * fix(howto/sockets.po): 更改專有名詞 gh-466 --------- Co-authored-by: Wei-Hsiang (Matt) Wang <[email protected]>
1 parent eda10c1 commit a1e5917

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

howto/sockets.po

+51-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgstr ""
88
"Project-Id-Version: Python 3.11\n"
99
"Report-Msgid-Bugs-To: \n"
1010
"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"
1212
"Last-Translator: Jay <[email protected]>\n"
1313
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1414
"tw)\n"
@@ -240,7 +240,7 @@ msgstr ""
240240
msgid ""
241241
"The :mod:`multiprocessing` integrates cross-platform IPC into a higher-level "
242242
"API."
243-
msgstr ":mod:`multiprocessing` 將跨平台的行程間通訊整合到更高層的 API 中。"
243+
msgstr ":mod:`multiprocessing` 將跨平台行程間通訊整合到更高層的 API 中。"
244244

245245
#: ../../howto/sockets.rst:134
246246
msgid "Using a Socket"
@@ -519,7 +519,7 @@ msgstr ""
519519

520520
#: ../../howto/sockets.rst:302
521521
msgid "When Sockets Die"
522-
msgstr ""
522+
msgstr "Sockets 何時銷毀"
523523

524524
#: ../../howto/sockets.rst:304
525525
msgid ""
@@ -535,10 +535,17 @@ msgid ""
535535
"automatic recycling of resources. In other words, if you do manage to kill "
536536
"the thread, your whole process is likely to be screwed up."
537537
msgstr ""
538+
"使用阻塞式 socket 最糟糕的地方可能是在另一端突然強制關閉(未執行 ``close``)"
539+
"的情況下會發生什麼?你的 socket 很可能會處於阻塞狀態。TCP 是一種可靠的協議,"
540+
"它在放棄連線之前會等待很長很長的時間。如果你正在使用執行緒,整個執行緒基本上"
541+
"已經無法使用。在這方面,你無法做太多事情。只要你不做一些愚蠢的事情,比如在"
542+
"執行阻塞式讀取時持有一個鎖,那麼執行緒並不會消耗太多資源。*不要*\\ 試圖終止"
543+
"執行緒 - 執行緒比行程更有效的部分原因是它們避免了與自動回收資源相關的開銷。換"
544+
"句話說,如果你確實設法終止了執行緒,整個行程可能會出現問題。"
538545

539546
#: ../../howto/sockets.rst:318
540547
msgid "Non-blocking Sockets"
541-
msgstr ""
548+
msgstr "非阻塞的 Sockets"
542549

543550
#: ../../howto/sockets.rst:320
544551
msgid ""
@@ -547,6 +554,9 @@ msgid ""
547554
"calls, in much the same ways. It's just that, if you do it right, your app "
548555
"will be almost inside-out."
549556
msgstr ""
557+
"如果你已經理解了前面的內容,你已經知道了大部分關於使用 sockets 的機制的所需知"
558+
"識,你仍然會以非常相似的方式使用相同的函式。就這樣而已,如果你做的對,你的程式"
559+
"就會是近乎完美的。"
550560

551561
#: ../../howto/sockets.rst:325
552562
msgid ""
@@ -557,6 +567,11 @@ msgid ""
557567
"the exact same idea. You do this after creating the socket, but before using "
558568
"it. (Actually, if you're nuts, you can switch back and forth.)"
559569
msgstr ""
570+
"在 Python 中可以使用 ``socket.setblocking(False)`` 來設定為非阻塞。在 C 的作"
571+
"法更為複雜(例如,你需要在 BSD 風格的 ``O_NONBLOCK`` 和幾乎沒有區別的 POSIX 風"
572+
"格的 ``O_NDELAY`` 之間做出選擇,這與 ``TCP_NODELAY`` 完全不同),但基本思想是"
573+
"一樣的,你要在建立 socket 後但在使用它之前執行此操作。(實際上,如果你願意的"
574+
"話,你甚至可以來回切換。)"
560575

561576
#: ../../howto/sockets.rst:332
562577
msgid ""
@@ -567,17 +582,24 @@ msgid ""
567582
"will grow large, buggy and suck CPU. So let's skip the brain-dead solutions "
568583
"and do it right."
569584
msgstr ""
585+
"主要的機制差異在於 ``send``、``recv``、``connect`` 和 ``accept`` 可能在沒有執"
586+
"行任何操作的情況下就回傳了。你當然有多種選擇。你可以檢查回傳值和錯誤代碼,但"
587+
"這些操作通常會讓自己抓狂。如果你不相信我,不妨試試看。你的應用程式會變得臃"
588+
"腫、錯誤百出,並且占用 CPU。所以,讓我們跳過無腦的解決方案,使用正確的方式。"
570589

571590
#: ../../howto/sockets.rst:339
572591
msgid "Use ``select``."
573-
msgstr ""
592+
msgstr "使用 ``select``。"
574593

575594
#: ../../howto/sockets.rst:341
576595
msgid ""
577596
"In C, coding ``select`` is fairly complex. In Python, it's a piece of cake, "
578597
"but it's close enough to the C version that if you understand ``select`` in "
579598
"Python, you'll have little trouble with it in C::"
580599
msgstr ""
600+
"在 C 中,編寫 ``select`` 是非常複雜的,但在 Python 中,這很簡單,並與 C 的版"
601+
"本非常類似,如果你理解了 Python 中的 ``select``,在 C 中處理它時也不會有太大"
602+
"的困難: ::"
581603

582604
#: ../../howto/sockets.rst:352
583605
msgid ""
@@ -589,13 +611,20 @@ msgid ""
589611
"generally a sensible thing to do - give it a nice long timeout (say a "
590612
"minute) unless you have good reason to do otherwise."
591613
msgstr ""
614+
"你傳遞給 ``select`` 三個列表:第一個列表包含你可能想要嘗試讀取的所有 "
615+
"sockets;第二個包含所有你可能想要嘗試寫入的 sockets,最後一個(通常為空)包含"
616+
"你想要檢查錯誤的 sockets。你應該注意,一個 socket 可以同時存在於多個列表中。"
617+
"``select`` 呼叫是阻塞的,但你可以設置超時。通常這是一個明智的做法 - 除非有"
618+
"充分的理由,否則給它一個很長的超時(比如一分鐘)。"
592619

593620
#: ../../howto/sockets.rst:360
594621
msgid ""
595622
"In return, you will get three lists. They contain the sockets that are "
596623
"actually readable, writable and in error. Each of these lists is a subset "
597624
"(possibly empty) of the corresponding list you passed in."
598625
msgstr ""
626+
"作為回傳,你將獲得三個列表。它們包含實際上可讀取、可寫入和出錯的 sockets。這"
627+
"些列表中的每一個都是你傳入的相應列表的子集(可能為空)。"
599628

600629
#: ../../howto/sockets.rst:364
601630
msgid ""
@@ -606,6 +635,11 @@ msgid ""
606635
"nothing. (Actually, any reasonably healthy socket will return as writable - "
607636
"it just means outbound network buffer space is available.)"
608637
msgstr ""
638+
"如果一個 socket 在輸出的可讀列表中,你可以幾乎確定,在這個業務中我們能夠得到"
639+
"的最接近確定的事情是,對該 socket 的 ``recv`` 呼叫將會回傳一些\\ *內容*。對於可寫"
640+
"列表,也是同樣的想法。你將能夠發送一些 *內容*。也許不是全部,但\\ *一些內容*\\ 總比"
641+
"什麼都沒有好。(實際上,任何比較正常的 socket 都會以可寫的方式回傳 - 這只是意味"
642+
"者「外送網路 (outbound network)」的緩衝空間是可用的。)"
609643

610644
#: ../../howto/sockets.rst:371
611645
msgid ""
@@ -615,6 +649,10 @@ msgid ""
615649
"it in the potential_writers list. If it shows up in the writable list, you "
616650
"have a decent chance that it has connected."
617651
msgstr ""
652+
"如果你有一個「伺服器端」socket,請將其放在 potential_readers 列表中,如果它在"
653+
"可讀列表中出現,你的 ``accept`` 呼叫(幾乎可以確定)會成功。如果你建立了一個"
654+
"新的 socket 去 ``connect`` 到其他地方,請將它放在 potential_writers 列表中,"
655+
"如果它在可寫列表中出現,那麼他有可能已經連接上了。"
618656

619657
#: ../../howto/sockets.rst:377
620658
msgid ""
@@ -624,6 +662,9 @@ msgid ""
624662
"problem of determining whether the other end is done, or just busy with "
625663
"something else."
626664
msgstr ""
665+
"實際上,即使是使用阻塞式 socket 的情況下,``select`` 也很方便。這是一種判斷是否"
666+
"會被阻塞的方法之一 - 當緩衝區中有某些內容時, socket 會回傳為可讀。然而,這"
667+
"仍然無法解決判斷另一端是否完成,或者只是忙於其他事情的問題。"
627668

628669
#: ../../howto/sockets.rst:382
629670
msgid ""
@@ -633,3 +674,8 @@ msgid ""
633674
"differently on Windows. In fact, on Windows I usually use threads (which "
634675
"work very, very well) with my sockets."
635676
msgstr ""
677+
"**可移植性警告**:在 Unix 上,``select`` 同時適用於 sockets 和文件。但請不要"
678+
"在 Windows 上嘗試這麼做,在 Windows 上,``select`` 只適用於 sockets。同時,請"
679+
"注意,在 C 語言中,許多更進階的 socket 選項在 Windows 上有不同的實現方式。實"
680+
"際上,在 Windows 上,我通常會使用執行緒(這非常,非常有效)與我的 sockets 一起"
681+
"使用。"

0 commit comments

Comments
 (0)