Opened 7 months ago

Closed 5 days ago

#36315 closed Cleanup/optimization (fixed)

Use task groups/cancel scopes where possible

Reported by: Thomas Grainger Owned by: Thomas Grainger
Component: HTTP handling Version: dev
Severity: Normal Keywords: async
Cc: Carlton Gibson Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Thomas Grainger)

eg replace asyncio.create_task with a Task Group
replace wait_for/wait with Timeout/CancelScope
create a function for asyncio.gather that uses a Task Group

This could use anyio.create_task_group and anyio.CancelScope, but now there's 3.11 asyncio.TaskGroup and asyncio.Timeout are available.

Obviously I'm biased and think the anyio versions are a better choice, but it's easier to add asyncio.TaskGroup/Timeout and worry about trio support in the 'future'.

Change History (8)

comment:1 by Thomas Grainger, 7 months ago

Description: modified (diff)
Owner: set to Thomas Grainger

comment:2 by Thomas Grainger, 7 months ago

Has patch: set

comment:3 by Carlton Gibson, 7 months ago

Cc: Carlton Gibson added
Component: UncategorizedHTTP handling
Keywords: async added
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Yes, this seems like a nice modernisation. Thanks.

comment:4 by Carlton Gibson, 7 months ago

Summary: use task groups/cancel scopes where possibleUse task groups/cancel scopes where possible

comment:5 by Carlton Gibson, 6 days ago

Triage Stage: AcceptedReady for checkin

I looked at both the PRs here, and they seem correct.

comment:6 by Jacob Walls <jacobtylerwalls@…>, 6 days ago

In 796cf3d3:

Refs #36315 -- Used contextlib.closing() in ASGIHandler.handle().

comment:7 by Jacob Walls <jacobtylerwalls@…>, 6 days ago

In 2501958:

Refs #36315 -- Replaced manual task and cancellation handling with TaskGroup in ASGIHandler.

comment:8 by Jacob Walls <jacobtylerwalls@…>, 5 days ago

Resolution: fixed
Status: assignedclosed

In 2768747:

Fixed #36315 -- Used TaskGroup instead of asyncio.gather().

Note: See TracTickets for help on using tickets.
Back to Top