Skip to content

gh-150116 Remove dead try/except in asyncio.Lock._wake_up_first#150117

Open
deadlovelll wants to merge 1 commit into
python:mainfrom
deadlovelll:gh-150116-wake-up-first-dead-code
Open

gh-150116 Remove dead try/except in asyncio.Lock._wake_up_first#150117
deadlovelll wants to merge 1 commit into
python:mainfrom
deadlovelll:gh-150116-wake-up-first-dead-code

Conversation

@deadlovelll
Copy link
Copy Markdown

@deadlovelll deadlovelll commented May 19, 2026

asyncio.Lock._wake_up_first had a try/except StopIteration block guarding next(iter(self._waiters)):

  def _wake_up_first(self):
      if not self._waiters:
          return
      try:
          fut = next(iter(self._waiters))
      except StopIteration:
          return
      ...

The except branch is unreachable. The preceding early return ensures self._waiters is a non-empty collections.deque

After:

  def _wake_up_first(self):
      if not self._waiters:
          return
      fut = next(iter(self._waiters))
      if not fut.done():
          fut.set_result(True)

No behavior change.

@bedevere-app
Copy link
Copy Markdown

bedevere-app Bot commented May 19, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@JelleZijlstra
Copy link
Copy Markdown
Member

Is it possible for another thread to add something to the container between the two checks?

@deadlovelll
Copy link
Copy Markdown
Author

Is it possible for another thread to add something to the container between the two checks?

Thanks for marking it. But asyncio primitives are not thread-safe. The official documentation says: link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants