Opened 11 months ago

Closed 6 months ago

#9546 enhancement closed fixed (fixed)

Allow using DeferredLock, DeferredSemaphore, etc as async context managers

Reported by: Wim Lewis Owned by: Tom Most
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch: 9546-async-context-manager
branch-diff, diff-cov, branch-cov, buildbot
Author:

Description

Python 3.4, and PEP 492, introduced "asynchronous context managers" and the "async with" statement: https://www.python.org/dev/peps/pep-0492/#asynchronous-context-managers-and-async-with

I think that twisted.internet.defer._ConcurrencyPrimitive should gain the __aenter__ / __aexit__ methods to allow its subclasses to be used as async context managers; this is the coroutine-syntax equivalent of the .run() method that it already has.

(In my own code, I've been using a subclass of DeferredLock with this addition for a while, and it seems like an idiom that's worth adding to Twisted.)

Change History (8)

comment:1 Changed 11 months ago by Wim Lewis

Owner: set to Wim Lewis
Status: newassigned

comment:2 Changed 10 months ago by Wim Lewis

Keywords: review added
Owner: Wim Lewis deleted
Status: assignednew

comment:3 Changed 10 months ago by Wim Lewis

Branch: 9546-async-context-manager

comment:4 Changed 7 months ago by Tom Most

Owner: set to Tom Most
Status: newassigned

comment:5 Changed 7 months ago by Tom Most

Keywords: review removed
Owner: changed from Tom Most to Wim Lewis
Status: assignednew

comment:6 Changed 6 months ago by Wim Lewis

Keywords: review added
Owner: changed from Wim Lewis to Tom Most

Ready for re-review

comment:7 Changed 6 months ago by Tom Most

Keywords: review removed

Re-reviewed: https://github.com/twisted/twisted/pull/1078 Will merge momentarily.

comment:8 Changed 6 months ago by Tom Most <twm@…>

Resolution: fixed
Status: newclosed

In c893dee:

Merge pull request #1078 from wiml/9546-async-context-manager

Author: wiml
Reviewer: twm
Fixes: ticket:9546

DeferredLock, DeferredSemaphore, etc as async context managers

Note: See TracTickets for help on using tickets.