Skip to content

Commit 30ecdef

Browse files
authored
Added stronger wording for lifespans/event loops
1 parent 6a0cae0 commit 30ecdef

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

specs/lifespan.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ Lifespan Protocol
55
**Version**: 2.0 (2019-03-20)
66

77
The Lifespan ASGI sub-specification outlines how to communicate
8-
lifespan events such as startup and shutdown within ASGI. This refers to the
9-
lifespan of the main event loop. In a multi-process environment there will be
10-
lifespan events in each process.
8+
lifespan events such as startup and shutdown within ASGI.
119

1210
The lifespan messages allow for an application to initialise and
1311
shutdown in the context of a running event loop. An example of this
1412
would be creating a connection pool and subsequently closing the
1513
connection pool to release the connections.
1614

15+
Lifespans should be executed once per event loop that will be processing requests.
16+
In a multi-process environment there will be lifespan events in each process
17+
and in a multi-threaded environment there will be lifespans for each thread.
18+
The important part is that lifespans and requests are run in the same event loop
19+
to ensure that objects like database connection pools are not moved or shared across event loops.
20+
1721
A possible implementation of this protocol is given below::
1822

1923
async def app(scope, receive, send):

0 commit comments

Comments
 (0)