File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -5,15 +5,19 @@ Lifespan Protocol
5
5
**Version **: 2.0 (2019-03-20)
6
6
7
7
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.
11
9
12
10
The lifespan messages allow for an application to initialise and
13
11
shutdown in the context of a running event loop. An example of this
14
12
would be creating a connection pool and subsequently closing the
15
13
connection pool to release the connections.
16
14
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
+
17
21
A possible implementation of this protocol is given below::
18
22
19
23
async def app(scope, receive, send):
You can’t perform that action at this time.
0 commit comments