Skip to content

Commit 1e581b1

Browse files
committed
feat(howto/sockets.po): 翻譯 When Sockets Die 和 Non-blocking Sockets 區塊
gh-466
1 parent eb9f39f commit 1e581b1

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

howto/sockets.po

Lines changed: 52 additions & 4 deletions
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 <weijay0804@gmail.com>\n"
1313
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1414
"tw)\n"
@@ -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+
"識,你仍然會以非常相似的方式使用相同的函式。只是,如果你做的對,#, fuzzy(這"
559+
"邊的 inside-out)不確定要怎麼翻。"
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,26 @@ 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+
"的困難\n"
603+
"\n"
604+
"::"
581605

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

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

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

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

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

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

0 commit comments

Comments
 (0)