This repository was archived by the owner on Jan 13, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,27 @@ Advanced Usage
55
66This section of the documentation covers more advanced use-cases for ``hyper ``.
77
8+ Responses as Context Managers
9+ -----------------------------
10+
11+ If you're concerned about having too many TCP sockets open at any one time, you
12+ may want to keep your connections alive only as long as you know you'll need
13+ them. In HTTP/2.0 this is generally not something you should do unless you're
14+ very confident you won't need the connection again anytime soon. However, if
15+ you decide you want to avoid keeping the connection open, you can use the
16+ :class: `HTTP20Connection <hyper.HTTP20Connection> ` as a context manager::
17+
18+ with HTTP20Connection('twitter.com:443') as conn:
19+ conn.request('GET', '/')
20+ data = conn.getresponse().read()
21+
22+ analyse(data)
23+
24+ You may not use any :class: `HTTP20Response <hyper.HTTP20Response> ` objects
25+ obtained from a connection after that connection is closed. Interacting with
26+ these objects when a connection has been closed is considered undefined
27+ behaviour.
28+
829Multithreading
930--------------
1031
You can’t perform that action at this time.
0 commit comments