Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-32253: Deprecate with statement and bare await for asyncio locks #4764

Merged
merged 10 commits into from
Dec 9, 2017

Conversation

asvetlov
Copy link
Contributor

@asvetlov asvetlov commented Dec 9, 2017


This class is :ref:`not thread safe <asyncio-multithreading>`.

Usage::
Copy link
Member

@1st1 1st1 Dec 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have one usage example with 'async with ...' syntax.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I see that you added a new section for that...

------------------------------------------------------------------------------

All of the objects provided by this module that have :meth:`acquire`
and :meth:`release` methods can be used as context managers for a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"can be used as context managers for a" -> "can be used in "async with" statements"


Currently, :class:`Lock`, :class:`Condition`,
:class:`Semaphore`, and :class:`BoundedSemaphore` objects may be used as
:keyword:`async with` statement context managers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit repetitive... I'd merge this paragraph with the first one:

":class:Lock, :class:Condition, :class:Semaphore, and :class:BoundedSemaphore can be used in "async with" statements."

synchronization primitives.

Explicit :meth:`acquire` / :meth:`release` calls should be used if
locking/unlocking is split into different functions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need these two paragraphs. People usually naturally prefer 'with' blocks when they are available.


.. deprecated:: 3.7

Lock acquiring on ``await lock`` or ``yield from lock`` and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Lock acquiring on" -> "Lock acquiring using"

@asvetlov
Copy link
Contributor Author

asvetlov commented Dec 9, 2017

All notes are fixed

@@ -260,6 +232,8 @@ Semaphore
defaults to ``1``. If the value given is less than ``0``, :exc:`ValueError`
is raised.

Locks also support the :ref:`context management protocol <async-with-locks>`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semaphores also support...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch


.. class:: BoundedSemaphore(value=1, \*, loop=None)

A bounded semaphore implementation. Inherit from :class:`Semaphore`.

This raises :exc:`ValueError` in :meth:`~Semaphore.release` if it would
increase the value above the initial value.

Locks also support the :ref:`context management protocol <async-with-locks>`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BoundedSemaphore also support...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@1st1
Copy link
Member

1st1 commented Dec 9, 2017

Spotted a few more nits; other than that it looks good

@asvetlov
Copy link
Contributor Author

asvetlov commented Dec 9, 2017

Fixed

@@ -139,7 +139,8 @@ Condition
object, and it is used as the underlying lock. Otherwise,
a new :class:`Lock` object is created and used as the underlying lock.

Locks also support the :ref:`context management protocol <async-with-locks>`.
Conditions also support the :ref:`context management protocol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last nit -- drop "also"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@1st1 1st1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. Thanks!

@asvetlov asvetlov merged commit 28d8d14 into python:master Dec 9, 2017
@asvetlov asvetlov deleted the bpo-32253 branch December 9, 2017 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants