|
45 | 45 | N_HTTP_CLIENTS = 100
|
46 | 46 |
|
47 | 47 |
|
48 |
| -def main(): |
| 48 | +def child_msg_generator(pipewriter): |
| 49 | + """I am executed in a child process. |
49 | 50 |
|
50 |
| - def servelet(http_server): |
51 |
| - """I am executed in a greenlet. |
| 51 | + I write some dummy payload to the write end of the pipe through which I |
| 52 | + am connected to my parent process. I terminate immediately after writing |
| 53 | + the message. |
| 54 | + """ |
| 55 | + pipewriter.put(DUMMY_PAYLOAD) |
52 | 56 |
|
53 |
| - It is my job to hang in the cooperatively blocking `serve_forever()` |
54 |
| - call to accept incoming connections. I only terminate when I am |
55 |
| - explicitly killed from the outside. |
56 |
| - """ |
57 |
| - http_server.serve_forever() |
| 57 | +def invoke_server_forever(http_server): |
| 58 | + """I am executed in a greenlet. |
58 | 59 |
|
59 |
| - def child_msg_generator(pipewriter): |
60 |
| - """I am executed in a child process. |
| 60 | + It is my job to hang in the cooperatively blocking `serve_forever()` |
| 61 | + call to accept incoming connections. I only terminate when I am |
| 62 | + explicitly killed from the outside. |
| 63 | + """ |
| 64 | + http_server.serve_forever() |
61 | 65 |
|
62 |
| - I write some dummy payload to the write end of the pipe through which I |
63 |
| - am connected to my parent process. I terminate immediately after writing |
64 |
| - the message. |
65 |
| - """ |
66 |
| - pipewriter.put(DUMMY_PAYLOAD) |
| 66 | +def main(): |
67 | 67 |
|
68 | 68 | def handle_http_request(_, start_response):
|
69 | 69 | """I am executed in a greenlet whenever an HTTP request came in."""
|
@@ -92,7 +92,7 @@ def handle_http_request(_, start_response):
|
92 | 92 | return [body]
|
93 | 93 |
|
94 | 94 | server = WSGIServer(('127.0.0.1', 0), handle_http_request, log=None)
|
95 |
| - servelet = gevent.spawn(servelet, server) |
| 95 | + servelet = gevent.spawn(invoke_server_forever, server) |
96 | 96 |
|
97 | 97 | # Wait for server to be bound to socket.
|
98 | 98 | while True:
|
@@ -131,6 +131,7 @@ def child_client_runner(server_address):
|
131 | 131 | """
|
132 | 132 |
|
133 | 133 | def get():
|
| 134 | + # Expected to throw an HTTPError when the response code is not 200. |
134 | 135 | body = request.urlopen('http://%s:%s/' % server_address).read()
|
135 | 136 | assert body == DUMMY_PAYLOAD
|
136 | 137 |
|
|
0 commit comments