# SOME DESCRIPTIVE TITLE. # Copyright (C) 2001-2025, Python Software Foundation # This file is distributed under the same license as the Python package. # FIRST AUTHOR , YEAR. # # Translators: # python-doc bot, 2025 # #, fuzzy msgid "" msgstr "" "Project-Id-Version: Python 3.9\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2025-09-22 21:56+0000\n" "PO-Revision-Date: 2025-09-22 17:54+0000\n" "Last-Translator: python-doc bot, 2025\n" "Language-Team: Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Language: zh_CN\n" "Plural-Forms: nplurals=1; plural=0;\n" #: ../../library/asyncio-sync.rst:7 msgid "Synchronization Primitives" msgstr "同步原语" #: ../../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` 模块的类似,但有两个关键注意事项:" #: ../../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 原语不是线程安全的,因此它们不应被用于 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 "这些同步原语的方法不接受 *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:37 msgid "Lock" msgstr "Lock" #: ../../library/asyncio-sync.rst:41 msgid "Implements a mutex lock for asyncio tasks. Not thread-safe." msgstr "实现一个用于 asyncio 任务的互斥锁。 非线程安全。" #: ../../library/asyncio-sync.rst:43 msgid "" "An asyncio lock can be used to guarantee exclusive access to a shared " "resource." msgstr "asyncio 锁可被用来保证对共享资源的独占访问。" #: ../../library/asyncio-sync.rst:46 msgid "" "The preferred way to use a Lock is an :keyword:`async with` statement::" msgstr "使用 Lock 的推荐方式是通过 :keyword:`async with` 语句::" #: ../../library/asyncio-sync.rst:55 ../../library/asyncio-sync.rst:200 #: ../../library/asyncio-sync.rst:300 msgid "which is equivalent to::" msgstr "这等价于::" #: ../../library/asyncio-sync.rst:68 ../../library/asyncio-sync.rst:114 #: ../../library/asyncio-sync.rst:190 ../../library/asyncio-sync.rst:290 #: ../../library/asyncio-sync.rst:345 msgid "The *loop* parameter." msgstr "" #: ../../library/asyncio-sync.rst:71 msgid "Acquire the lock." msgstr "获取锁。" #: ../../library/asyncio-sync.rst:73 msgid "" "This method waits until the lock is *unlocked*, sets it to *locked* and " "returns ``True``." msgstr "此方法会等待直至锁为 *unlocked*,将其设为 *locked* 并返回 ``True``。" #: ../../library/asyncio-sync.rst:76 msgid "" "When more than one coroutine is blocked in :meth:`acquire` waiting for the " "lock to be unlocked, only one coroutine eventually proceeds." msgstr "当有一个以上的协程在 :meth:`acquire` 中被阻塞则会等待解锁,最终只有一个协程会被执行。" #: ../../library/asyncio-sync.rst:80 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:85 msgid "Release the lock." msgstr "释放锁。" #: ../../library/asyncio-sync.rst:87 msgid "When the lock is *locked*, reset it to *unlocked* and return." msgstr "当锁为 *locked* 时,将其设为 *unlocked* 并返回。" #: ../../library/asyncio-sync.rst:89 msgid "If the lock is *unlocked*, a :exc:`RuntimeError` is raised." msgstr "如果锁为 *unlocked*,则会引发 :exc:`RuntimeError`。" #: ../../library/asyncio-sync.rst:93 msgid "Return ``True`` if the lock is *locked*." msgstr "如果锁为 *locked* 则返回 ``True``。" #: ../../library/asyncio-sync.rst:97 msgid "Event" msgstr "事件" #: ../../library/asyncio-sync.rst:101 msgid "An event object. Not thread-safe." msgstr "事件对象。 该对象不是线程安全的。" #: ../../library/asyncio-sync.rst:103 msgid "" "An asyncio event can be used to notify multiple asyncio tasks that some " "event has happened." msgstr "asyncio 事件可被用来通知多个 asyncio 任务已经有事件发生。" #: ../../library/asyncio-sync.rst:106 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 对象会管理一个内部旗标,可通过 :meth:`~Event.set` 方法将其设为 *true* 并通过 :meth:`clear` " "方法将其重设为 *false*。 :meth:`~Event.wait` 方法会阻塞直至该旗标被设为 *true*。 该旗标初始时会被设为 " "*false*。" #: ../../library/asyncio-sync.rst:117 msgid "Example::" 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` 进行等待的任务现在将会阻塞直至 :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 "条件对象。 该对象不是线程安全的。" #: ../../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:191 msgid "" "The preferred way to use a Condition is an :keyword:`async with` statement::" msgstr "使用 Condition 的推荐方式是通过 :keyword:`async with` 语句::" #: ../../library/asyncio-sync.rst:213 msgid "Acquire the underlying lock." msgstr "获取下层的锁。" #: ../../library/asyncio-sync.rst:215 msgid "" "This method waits until the underlying lock is *unlocked*, sets it to " "*locked* and returns ``True``." msgstr "此方法会等待直至下层的锁为 *unlocked*,将其设为 *locked* 并返回 returns ``True``。" #: ../../library/asyncio-sync.rst:220 msgid "" "Wake up at most *n* tasks (1 by default) waiting on this condition. The " "method is no-op if no tasks are waiting." msgstr "唤醒最多 *n* 个正在等待此条件的任务(默认为 1 个)。 如果没有任务正在等待则此方法为空操作。" #: ../../library/asyncio-sync.rst:223 ../../library/asyncio-sync.rst:238 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:229 msgid "Return ``True`` if the underlying lock is acquired." msgstr "如果下层的锁已被获取则返回 ``True``。" #: ../../library/asyncio-sync.rst:233 msgid "Wake up all tasks waiting on this condition." msgstr "唤醒所有正在等待此条件的任务。" #: ../../library/asyncio-sync.rst:235 msgid "This method acts like :meth:`notify`, but wakes up all waiting tasks." msgstr "此方法的行为类似于 :meth:`notify`,但会唤醒所有正在等待的任务。" #: ../../library/asyncio-sync.rst:244 msgid "Release the underlying lock." msgstr "释放下层的锁。" #: ../../library/asyncio-sync.rst:246 msgid "When invoked on an unlocked lock, a :exc:`RuntimeError` is raised." msgstr "当在未锁定的锁上唤起时,会引发 :exc:`RuntimeError`。" #: ../../library/asyncio-sync.rst:251 msgid "Wait until notified." msgstr "等待直至收到通知。" #: ../../library/asyncio-sync.rst:253 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:256 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:263 msgid "Wait until a predicate becomes *true*." msgstr "等待直到目标值变为 *true*。" #: ../../library/asyncio-sync.rst:265 msgid "" "The predicate must be a callable which result will be interpreted as a " "boolean value. The final value is the return value." msgstr "目标必须为一个可调用对象,其结果将被解读为一个布尔值。 最终的值将为返回值。" #: ../../library/asyncio-sync.rst:271 msgid "Semaphore" msgstr "Semaphore" #: ../../library/asyncio-sync.rst:275 msgid "A Semaphore object. Not thread-safe." msgstr "信号量对象。 该对象不是线程安全的。" #: ../../library/asyncio-sync.rst:277 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:283 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:291 msgid "" "The preferred way to use a Semaphore is an :keyword:`async with` statement::" msgstr "使用 Semaphore 的推荐方式是通过 :keyword:`async with` 语句。::" #: ../../library/asyncio-sync.rst:313 msgid "Acquire a semaphore." msgstr "获取一个信号量。" #: ../../library/asyncio-sync.rst:315 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:321 msgid "Returns ``True`` if semaphore can not be acquired immediately." msgstr "如果信号量对象无法被立即获取则返回 ``True``。" #: ../../library/asyncio-sync.rst:325 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:328 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:333 msgid "BoundedSemaphore" msgstr "BoundedSemaphore" #: ../../library/asyncio-sync.rst:337 msgid "A bounded semaphore object. Not thread-safe." msgstr "绑定的信号量对象。 该对象不是线程安全的。" #: ../../library/asyncio-sync.rst:339 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 "" "BoundedSemaphore 是特殊版本的 :class:`Semaphore`,如果在 :meth:`~Semaphore.release` " "中内部计数器值增加到初始 *value* 以上它将引发一个 :exc:`ValueError`。" #: ../../library/asyncio-sync.rst:352 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``。"