-
-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathasyncio-sync.po
676 lines (576 loc) · 22.9 KB
/
asyncio-sync.po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
# Copyright (C) 2001-2022, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-30 00:14+0000\n"
"PO-Revision-Date: 2022-02-09 19:27+0800\n"
"Last-Translator: Adrian Liaw <[email protected]>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.0.1\n"
#: ../../library/asyncio-sync.rst:7
msgid "Synchronization Primitives"
msgstr "同步化原始物件 (Synchronization Primitives)"
#: ../../library/asyncio-sync.rst:9
msgid "**Source code:** :source:`Lib/asyncio/locks.py`"
msgstr "**原始碼:**\\ :source:`Lib/asyncio/locks.py`"
#: ../../library/asyncio-sync.rst:13
msgid ""
"asyncio synchronization primitives are designed to be similar to those of "
"the :mod:`threading` module with two important caveats:"
msgstr ""
"asyncio 的同步化原始物件被設計成和那些 :mod:`threading` 模組 (module) 中的同"
"名物件相似,但有兩個重要的限制條件:"
#: ../../library/asyncio-sync.rst:16
msgid ""
"asyncio primitives are not thread-safe, therefore they should not be used "
"for OS thread synchronization (use :mod:`threading` for that);"
msgstr ""
"asyncio 原始物件並不支援執行緒安全 (thread-safe),因此他們不可被用於 OS 執行"
"緒同步化(請改用 :mod:`threading`\\ );"
#: ../../library/asyncio-sync.rst:20
msgid ""
"methods of these synchronization primitives do not accept the *timeout* "
"argument; use the :func:`asyncio.wait_for` function to perform operations "
"with timeouts."
msgstr ""
"這些同步化原始物件的方法 (method) 並不接受 *timeout* 引數;要達成有超時 "
"(timeout) 設定的操作請改用 :func:`asyncio.wait_for` 函式。"
#: ../../library/asyncio-sync.rst:24
msgid "asyncio has the following basic synchronization primitives:"
msgstr "asyncio 有以下基礎同步化原始物件:"
#: ../../library/asyncio-sync.rst:26
msgid ":class:`Lock`"
msgstr ":class:`Lock`"
#: ../../library/asyncio-sync.rst:27
msgid ":class:`Event`"
msgstr ":class:`Event`"
#: ../../library/asyncio-sync.rst:28
msgid ":class:`Condition`"
msgstr ":class:`Condition`"
#: ../../library/asyncio-sync.rst:29
msgid ":class:`Semaphore`"
msgstr ":class:`Semaphore`"
#: ../../library/asyncio-sync.rst:30
msgid ":class:`BoundedSemaphore`"
msgstr ":class:`BoundedSemaphore`"
#: ../../library/asyncio-sync.rst:31
msgid ":class:`Barrier`"
msgstr ":class:`Barrier`"
#: ../../library/asyncio-sync.rst:38
msgid "Lock"
msgstr "Lock"
#: ../../library/asyncio-sync.rst:42
msgid "Implements a mutex lock for asyncio tasks. Not thread-safe."
msgstr ""
"實作了一個給 asyncio 任務 (task) 用的互斥鎖 (mutex lock)。不支援執行緒安全。"
#: ../../library/asyncio-sync.rst:44
msgid ""
"An asyncio lock can be used to guarantee exclusive access to a shared "
"resource."
msgstr "一個 asyncio 的鎖可以用來確保一個共享資源的存取權被獨佔。"
#: ../../library/asyncio-sync.rst:47
msgid "The preferred way to use a Lock is an :keyword:`async with` statement::"
msgstr "使用 Lock 的推薦方式是透過 :keyword:`async with` 陳述式: ::"
#: ../../library/asyncio-sync.rst:50
msgid ""
"lock = asyncio.Lock()\n"
"\n"
"# ... later\n"
"async with lock:\n"
" # access shared state"
msgstr ""
#: ../../library/asyncio-sync.rst:56 ../../library/asyncio-sync.rst:199
#: ../../library/asyncio-sync.rst:304
msgid "which is equivalent to::"
msgstr "這等價於: ::"
#: ../../library/asyncio-sync.rst:58
msgid ""
"lock = asyncio.Lock()\n"
"\n"
"# ... later\n"
"await lock.acquire()\n"
"try:\n"
" # access shared state\n"
"finally:\n"
" lock.release()"
msgstr ""
#: ../../library/asyncio-sync.rst:67 ../../library/asyncio-sync.rst:112
#: ../../library/asyncio-sync.rst:187 ../../library/asyncio-sync.rst:292
#: ../../library/asyncio-sync.rst:347
msgid "Removed the *loop* parameter."
msgstr "移除 ``loop`` 參數。"
#: ../../library/asyncio-sync.rst:72
msgid "Acquire the lock."
msgstr "獲得鎖。"
#: ../../library/asyncio-sync.rst:74
msgid ""
"This method waits until the lock is *unlocked*, sets it to *locked* and "
"returns ``True``."
msgstr ""
"此方法會持續等待直到鎖的狀態成為 *unlocked*,並將其設置為 *locked* 和回傳 "
"``True``。"
#: ../../library/asyncio-sync.rst:77
msgid ""
"When more than one coroutine is blocked in :meth:`acquire` waiting for the "
"lock to be unlocked, only one coroutine eventually proceeds."
msgstr ""
"當多於一個的協程 (coroutine) 在 :meth:`acquire` 中等待解鎖而被阻塞,最終只會"
"有其中的一個被處理。"
#: ../../library/asyncio-sync.rst:81
msgid ""
"Acquiring a lock is *fair*: the coroutine that proceeds will be the first "
"coroutine that started waiting on the lock."
msgstr ""
"鎖的取得方式是\\ *公平*\\ 的:被處理的協程會是最早開始等待解鎖的那一個。"
#: ../../library/asyncio-sync.rst:86
msgid "Release the lock."
msgstr "釋放鎖。"
#: ../../library/asyncio-sync.rst:88
msgid "When the lock is *locked*, reset it to *unlocked* and return."
msgstr "如果鎖的狀態為 *locked* 則將其重置為 *unlocked* 並回傳。"
#: ../../library/asyncio-sync.rst:90
msgid "If the lock is *unlocked*, a :exc:`RuntimeError` is raised."
msgstr "如果鎖的狀態為 *unlocked* 則 :exc:`RuntimeError` 會被引發。"
#: ../../library/asyncio-sync.rst:94
msgid "Return ``True`` if the lock is *locked*."
msgstr "如果鎖的狀態為 *locked* 則回傳 ``True``。"
#: ../../library/asyncio-sync.rst:98
msgid "Event"
msgstr "Event"
#: ../../library/asyncio-sync.rst:102
msgid "An event object. Not thread-safe."
msgstr "一個事件 (event) 物件。不支援執行緒安全。"
#: ../../library/asyncio-sync.rst:104
msgid ""
"An asyncio event can be used to notify multiple asyncio tasks that some "
"event has happened."
msgstr ""
"一個 asyncio 事件可以被用於通知多個有發生某些事件於其中的 asyncio 任務。"
#: ../../library/asyncio-sync.rst:107
msgid ""
"An Event object manages an internal flag that can be set to *true* with the :"
"meth:`~Event.set` method and reset to *false* with the :meth:`clear` "
"method. The :meth:`~Event.wait` method blocks until the flag is set to "
"*true*. The flag is set to *false* initially."
msgstr ""
"一個 Event 物件會管理一個內部旗標 (flag),它可以透過 :meth:`~Event.set` 方法"
"來被設為 *true* 並透過 :meth:`clear` 方法來重置為 *false*。:meth:`~Event."
"wait` 方法會被阻塞 (block) 直到該旗標被設為 *true*。該旗標初始設置為 "
"*false*。"
#: ../../library/asyncio-sync.rst:117 ../../library/asyncio-sync.rst:371
msgid "Example::"
msgstr "範例: ::"
#: ../../library/asyncio-sync.rst:119
msgid ""
"async def waiter(event):\n"
" print('waiting for it ...')\n"
" await event.wait()\n"
" print('... got it!')\n"
"\n"
"async def main():\n"
" # Create an Event object.\n"
" event = asyncio.Event()\n"
"\n"
" # Spawn a Task to wait until 'event' is set.\n"
" waiter_task = asyncio.create_task(waiter(event))\n"
"\n"
" # Sleep for 1 second and set the event.\n"
" await asyncio.sleep(1)\n"
" event.set()\n"
"\n"
" # Wait until the waiter task is finished.\n"
" await waiter_task\n"
"\n"
"asyncio.run(main())"
msgstr ""
#: ../../library/asyncio-sync.rst:142
msgid "Wait until the event is set."
msgstr "持續等待直到事件被設置。"
#: ../../library/asyncio-sync.rst:144
msgid ""
"If the event is set, return ``True`` immediately. Otherwise block until "
"another task calls :meth:`~Event.set`."
msgstr ""
"如果事件有被設置則立刻回傳 ``True``。否則持續阻塞直到另一個任務呼叫 :meth:"
"`~Event.set`。"
#: ../../library/asyncio-sync.rst:149
msgid "Set the event."
msgstr "設置事件。"
#: ../../library/asyncio-sync.rst:151
msgid "All tasks waiting for event to be set will be immediately awakened."
msgstr "所有正在等待事件被設置的任務會立即被喚醒。"
#: ../../library/asyncio-sync.rst:156
msgid "Clear (unset) the event."
msgstr "清除(還原)事件。"
#: ../../library/asyncio-sync.rst:158
msgid ""
"Tasks awaiting on :meth:`~Event.wait` will now block until the :meth:`~Event."
"set` method is called again."
msgstr ""
"正透過 :meth:`~Event.wait` 等待的 Tasks 現在會持續阻塞直到 :meth:`~Event."
"set` 方法再次被呼叫。"
#: ../../library/asyncio-sync.rst:163
msgid "Return ``True`` if the event is set."
msgstr "如果事件有被設置則回傳 ``True``。"
#: ../../library/asyncio-sync.rst:167
msgid "Condition"
msgstr "Condition"
#: ../../library/asyncio-sync.rst:171
msgid "A Condition object. Not thread-safe."
msgstr "一個條件 (codition) 物件。不支援執行緒安全。"
#: ../../library/asyncio-sync.rst:173
msgid ""
"An asyncio condition primitive can be used by a task to wait for some event "
"to happen and then get exclusive access to a shared resource."
msgstr ""
"一個 asyncio 條件原始物件可以被任務用來等待某事件發生,並獲得一個共享資源的獨"
"佔存取權。"
#: ../../library/asyncio-sync.rst:177
msgid ""
"In essence, a Condition object combines the functionality of an :class:"
"`Event` and a :class:`Lock`. It is possible to have multiple Condition "
"objects share one Lock, which allows coordinating exclusive access to a "
"shared resource between different tasks interested in particular states of "
"that shared resource."
msgstr ""
"本質上,一個 Condition 物件會結合 :class:`Event` 和 :class:`Lock` 的功能。多"
"個 Condition 物件共享一個 Lock 是有可能發生的,這能夠協調關注同一共享資源的不"
"同狀態以取得其獨佔存取權的多個任務。"
#: ../../library/asyncio-sync.rst:183
msgid ""
"The optional *lock* argument must be a :class:`Lock` object or ``None``. In "
"the latter case a new Lock object is created automatically."
msgstr ""
"可選的 *lock* 引數必須是一個 :class:`Lock` 物件或者為 ``None``。如為後者則一"
"個新的 Lock 物件會被自動建立。"
#: ../../library/asyncio-sync.rst:190
msgid ""
"The preferred way to use a Condition is an :keyword:`async with` statement::"
msgstr "使用 Condition 的推薦方式是透過 :keyword:`async with` 陳述式: ::"
#: ../../library/asyncio-sync.rst:193
msgid ""
"cond = asyncio.Condition()\n"
"\n"
"# ... later\n"
"async with cond:\n"
" await cond.wait()"
msgstr ""
#: ../../library/asyncio-sync.rst:201
msgid ""
"cond = asyncio.Condition()\n"
"\n"
"# ... later\n"
"await cond.acquire()\n"
"try:\n"
" await cond.wait()\n"
"finally:\n"
" cond.release()"
msgstr ""
#: ../../library/asyncio-sync.rst:212
msgid "Acquire the underlying lock."
msgstr "取得底層的鎖。"
#: ../../library/asyncio-sync.rst:214
msgid ""
"This method waits until the underlying lock is *unlocked*, sets it to "
"*locked* and returns ``True``."
msgstr ""
"此方法會持續等待直到底層的鎖為 *unlocked*,並將其設為 *locked* 並回傳 "
"``True``。"
#: ../../library/asyncio-sync.rst:219
msgid ""
"Wake up *n* tasks (1 by default) waiting on this condition. If fewer than "
"*n* tasks are waiting they are all awakened."
msgstr ""
"喚醒至多 *n* 個正在等待此條件的任務(預設為 1),如果少於 *n* 個任務則全部被"
"喚醒。"
#: ../../library/asyncio-sync.rst:222 ../../library/asyncio-sync.rst:237
msgid ""
"The lock must be acquired before this method is called and released shortly "
"after. If called with an *unlocked* lock a :exc:`RuntimeError` error is "
"raised."
msgstr ""
"在此方法被呼叫前必須先獲得鎖,並在之後立刻將其釋放。如果呼叫於一個 "
"*unlocked* 的鎖則 :exc:`RuntimeError` 錯誤會被引發。"
#: ../../library/asyncio-sync.rst:228
msgid "Return ``True`` if the underlying lock is acquired."
msgstr "如果已取得底層的鎖則回傳 ``True``。"
#: ../../library/asyncio-sync.rst:232
msgid "Wake up all tasks waiting on this condition."
msgstr "喚醒所有正在等待此條件的任務。"
#: ../../library/asyncio-sync.rst:234
msgid "This method acts like :meth:`notify`, but wakes up all waiting tasks."
msgstr "這個方法的行為就像 :meth:`notify`,但會喚醒所有正在等待的任務。"
#: ../../library/asyncio-sync.rst:243
msgid "Release the underlying lock."
msgstr "釋放底層的鎖。"
#: ../../library/asyncio-sync.rst:245
msgid "When invoked on an unlocked lock, a :exc:`RuntimeError` is raised."
msgstr "當叫用於一個未被解開的鎖之上時,會引發一個 :exc:`RuntimeError`。"
#: ../../library/asyncio-sync.rst:250
msgid "Wait until notified."
msgstr "持續等待直到被通知 (notify)。"
#: ../../library/asyncio-sync.rst:252
msgid ""
"If the calling task has not acquired the lock when this method is called, a :"
"exc:`RuntimeError` is raised."
msgstr ""
"當此方法被呼叫時,如果呼叫它的任務還沒有取得鎖的話,:exc:`RuntimeError` 會被"
"引發。"
#: ../../library/asyncio-sync.rst:255
msgid ""
"This method releases the underlying lock, and then blocks until it is "
"awakened by a :meth:`notify` or :meth:`notify_all` call. Once awakened, the "
"Condition re-acquires its lock and this method returns ``True``."
msgstr ""
"此方法會釋放底層的鎖,然後持續阻塞直到被 :meth:`notify` 或 :meth:"
"`notify_all` 的呼叫所喚醒。一但被喚醒,Condition 會重新取得該鎖且此方法會回"
"傳 ``True``。"
#: ../../library/asyncio-sync.rst:260
msgid ""
"Note that a task *may* return from this call spuriously, which is why the "
"caller should always re-check the state and be prepared to :meth:`~Condition."
"wait` again. For this reason, you may prefer to use :meth:`~Condition."
"wait_for` instead."
msgstr ""
#: ../../library/asyncio-sync.rst:267
msgid "Wait until a predicate becomes *true*."
msgstr "持續等待直到謂語 (predicate) 成為 *true*。"
#: ../../library/asyncio-sync.rst:269
msgid ""
"The predicate must be a callable which result will be interpreted as a "
"boolean value. The method will repeatedly :meth:`~Condition.wait` until the "
"predicate evaluates to *true*. The final value is the return value."
msgstr ""
"謂語必須是一個結果可被直譯為一個 boolean 值的可呼叫物件 (callable)。此方法會"
"重複地 :meth:`~Condition.wait` 直到謂語求值結果為 *true*。最終的值即為回傳"
"值。"
#: ../../library/asyncio-sync.rst:276
msgid "Semaphore"
msgstr "Semaphore"
#: ../../library/asyncio-sync.rst:280
msgid "A Semaphore object. Not thread-safe."
msgstr "一個旗號 (semaphore) 物件。不支援執行緒安全。"
#: ../../library/asyncio-sync.rst:282
msgid ""
"A semaphore manages an internal counter which is decremented by each :meth:"
"`acquire` call and incremented by each :meth:`release` call. The counter can "
"never go below zero; when :meth:`acquire` finds that it is zero, it blocks, "
"waiting until some task calls :meth:`release`."
msgstr ""
"一個旗號物件會管理一個內部計數器,會在每次呼叫 :meth:`acquire` 時減少一、每次"
"呼叫 :meth:`release` 時增加一。此計數器永遠不會少於零;當 :meth:`acquire` 發"
"現它是零時,它會持續阻塞並等待某任務呼叫 :meth:`release`。"
#: ../../library/asyncio-sync.rst:288
msgid ""
"The optional *value* argument gives the initial value for the internal "
"counter (``1`` by default). If the given value is less than ``0`` a :exc:"
"`ValueError` is raised."
msgstr ""
"可選的 *value* 引數給定了內部計數器的初始值(預設為 ``1``\\ )。如給定的值少"
"於 ``0`` 則 :exc:`ValueError` 會被引發。"
#: ../../library/asyncio-sync.rst:295
msgid ""
"The preferred way to use a Semaphore is an :keyword:`async with` statement::"
msgstr "使用 Semaphore 的推薦方式是透過 :keyword:`async with` 陳述式: ::"
#: ../../library/asyncio-sync.rst:298
msgid ""
"sem = asyncio.Semaphore(10)\n"
"\n"
"# ... later\n"
"async with sem:\n"
" # work with shared resource"
msgstr ""
#: ../../library/asyncio-sync.rst:306
msgid ""
"sem = asyncio.Semaphore(10)\n"
"\n"
"# ... later\n"
"await sem.acquire()\n"
"try:\n"
" # work with shared resource\n"
"finally:\n"
" sem.release()"
msgstr ""
#: ../../library/asyncio-sync.rst:317
msgid "Acquire a semaphore."
msgstr "取得一個旗號。"
#: ../../library/asyncio-sync.rst:319
msgid ""
"If the internal counter is greater than zero, decrement it by one and return "
"``True`` immediately. If it is zero, wait until a :meth:`release` is called "
"and return ``True``."
msgstr ""
"如果內部計數器大於零,將其減一並立刻回傳 ``True``。如果為零,則持續等待直到 :"
"meth:`release` 被呼叫,並回傳 ``True``。"
#: ../../library/asyncio-sync.rst:325
msgid "Returns ``True`` if semaphore can not be acquired immediately."
msgstr "如果旗號無法立即被取得則回傳 ``True``。"
#: ../../library/asyncio-sync.rst:329
msgid ""
"Release a semaphore, incrementing the internal counter by one. Can wake up a "
"task waiting to acquire the semaphore."
msgstr ""
"釋放一個旗號,並為其內部的計數器數值增加一。可以把一個正在等待取得旗號的任務"
"叫醒。"
#: ../../library/asyncio-sync.rst:332
msgid ""
"Unlike :class:`BoundedSemaphore`, :class:`Semaphore` allows making more "
"``release()`` calls than ``acquire()`` calls."
msgstr ""
"和 :class:`BoundedSemaphore` 不同,:class:`Semaphore` 允許 ``release()`` 的呼"
"叫次數多於 ``acquire()``。"
#: ../../library/asyncio-sync.rst:337
msgid "BoundedSemaphore"
msgstr "BoundedSemaphore"
#: ../../library/asyncio-sync.rst:341
msgid "A bounded semaphore object. Not thread-safe."
msgstr "一個有界的旗號物件。不支援執行緒安全。"
#: ../../library/asyncio-sync.rst:343
msgid ""
"Bounded Semaphore is a version of :class:`Semaphore` that raises a :exc:"
"`ValueError` in :meth:`~Semaphore.release` if it increases the internal "
"counter above the initial *value*."
msgstr ""
"Bounded Semaphore 是 :class:`Semaphore` 的另一版本,如果其內部的計數器數值增"
"加至大於初始 *value* 值的話,:exc:`ValueError` 會在 :meth:`~Semaphore."
"release` 時被引發。"
#: ../../library/asyncio-sync.rst:352
msgid "Barrier"
msgstr "Barrier"
#: ../../library/asyncio-sync.rst:356
msgid "A barrier object. Not thread-safe."
msgstr "一個屏障 (barrier) 物件。不支援執行緒安全。"
#: ../../library/asyncio-sync.rst:358
msgid ""
"A barrier is a simple synchronization primitive that allows to block until "
"*parties* number of tasks are waiting on it. Tasks can wait on the :meth:"
"`~Barrier.wait` method and would be blocked until the specified number of "
"tasks end up waiting on :meth:`~Barrier.wait`. At that point all of the "
"waiting tasks would unblock simultaneously."
msgstr ""
#: ../../library/asyncio-sync.rst:364
msgid ""
":keyword:`async with` can be used as an alternative to awaiting on :meth:"
"`~Barrier.wait`."
msgstr ""
#: ../../library/asyncio-sync.rst:367
msgid "The barrier can be reused any number of times."
msgstr ""
#: ../../library/asyncio-sync.rst:373
msgid ""
"async def example_barrier():\n"
" # barrier with 3 parties\n"
" b = asyncio.Barrier(3)\n"
"\n"
" # create 2 new waiting tasks\n"
" asyncio.create_task(b.wait())\n"
" asyncio.create_task(b.wait())\n"
"\n"
" await asyncio.sleep(0)\n"
" print(b)\n"
"\n"
" # The third .wait() call passes the barrier\n"
" await b.wait()\n"
" print(b)\n"
" print(\"barrier passed\")\n"
"\n"
" await asyncio.sleep(0)\n"
" print(b)\n"
"\n"
"asyncio.run(example_barrier())"
msgstr ""
#: ../../library/asyncio-sync.rst:394
msgid "Result of this example is::"
msgstr ""
#: ../../library/asyncio-sync.rst:396
msgid ""
"<asyncio.locks.Barrier object at 0x... [filling, waiters:2/3]>\n"
"<asyncio.locks.Barrier object at 0x... [draining, waiters:0/3]>\n"
"barrier passed\n"
"<asyncio.locks.Barrier object at 0x... [filling, waiters:0/3]>"
msgstr ""
"<asyncio.locks.Barrier object at 0x... [filling, waiters:2/3]>\n"
"<asyncio.locks.Barrier object at 0x... [draining, waiters:0/3]>\n"
"barrier passed\n"
"<asyncio.locks.Barrier object at 0x... [filling, waiters:0/3]>"
#: ../../library/asyncio-sync.rst:405
msgid ""
"Pass the barrier. When all the tasks party to the barrier have called this "
"function, they are all unblocked simultaneously."
msgstr ""
#: ../../library/asyncio-sync.rst:408
msgid ""
"When a waiting or blocked task in the barrier is cancelled, this task exits "
"the barrier which stays in the same state. If the state of the barrier is "
"\"filling\", the number of waiting task decreases by 1."
msgstr ""
#: ../../library/asyncio-sync.rst:413
msgid ""
"The return value is an integer in the range of 0 to ``parties-1``, different "
"for each task. This can be used to select a task to do some special "
"housekeeping, e.g.::"
msgstr ""
#: ../../library/asyncio-sync.rst:417
msgid ""
"...\n"
"async with barrier as position:\n"
" if position == 0:\n"
" # Only one task prints this\n"
" print('End of *draining phase*')"
msgstr ""
#: ../../library/asyncio-sync.rst:423
msgid ""
"This method may raise a :class:`BrokenBarrierError` exception if the barrier "
"is broken or reset while a task is waiting. It could raise a :exc:"
"`CancelledError` if a task is cancelled."
msgstr ""
#: ../../library/asyncio-sync.rst:429
msgid ""
"Return the barrier to the default, empty state. Any tasks waiting on it "
"will receive the :class:`BrokenBarrierError` exception."
msgstr ""
#: ../../library/asyncio-sync.rst:432
msgid ""
"If a barrier is broken it may be better to just leave it and create a new "
"one."
msgstr ""
#: ../../library/asyncio-sync.rst:436
msgid ""
"Put the barrier into a broken state. This causes any active or future calls "
"to :meth:`~Barrier.wait` to fail with the :class:`BrokenBarrierError`. Use "
"this for example if one of the tasks needs to abort, to avoid infinite "
"waiting tasks."
msgstr ""
#: ../../library/asyncio-sync.rst:443
msgid "The number of tasks required to pass the barrier."
msgstr ""
#: ../../library/asyncio-sync.rst:447
msgid "The number of tasks currently waiting in the barrier while filling."
msgstr ""
#: ../../library/asyncio-sync.rst:451
msgid "A boolean that is ``True`` if the barrier is in the broken state."
msgstr ""
#: ../../library/asyncio-sync.rst:456
msgid ""
"This exception, a subclass of :exc:`RuntimeError`, is raised when the :class:"
"`Barrier` object is reset or broken."
msgstr ""
#: ../../library/asyncio-sync.rst:464
msgid ""
"Acquiring a lock using ``await lock`` or ``yield from lock`` and/or :keyword:"
"`with` statement (``with await lock``, ``with (yield from lock)``) was "
"removed. Use ``async with lock`` instead."
msgstr ""
"透過 ``await lock`` 或 ``yield from lock`` 和/或 :keyword:`with` 陳述式 "
"(``with await lock``, ``with (yield from lock)``) 來取得鎖的方式已被移除。請"
"改用 ``async with lock``。"