Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: native_client_sdk/src/examples/httpd.py

Issue 10821046: Python webserver output flushing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A tiny web server. 6 """A tiny web server.
7 7
8 This is intended to be used for testing, and only run from within the examples 8 This is intended to be used for testing, and only run from within the examples
9 directory. 9 directory.
10 """ 10 """
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 # An HTTP server that will quit when |is_running| is set to False. We also use 61 # An HTTP server that will quit when |is_running| is set to False. We also use
62 # SocketServer.ThreadingMixIn in order to handle requests asynchronously for 62 # SocketServer.ThreadingMixIn in order to handle requests asynchronously for
63 # faster responses. 63 # faster responses.
64 class QuittableHTTPServer(SocketServer.ThreadingMixIn, 64 class QuittableHTTPServer(SocketServer.ThreadingMixIn,
65 BaseHTTPServer.HTTPServer): 65 BaseHTTPServer.HTTPServer):
66 def serve_forever(self, timeout=0.5): 66 def serve_forever(self, timeout=0.5):
67 self.is_running = True 67 self.is_running = True
68 self.timeout = timeout 68 self.timeout = timeout
69 while self.is_running: 69 while self.is_running:
70 sys.stderr.flush()
noelallen1 2012/07/26 21:11:04 Should be harmless, but I would expect stderr to b
71 sys.stdout.flush()
70 self.handle_request() 72 self.handle_request()
71 73
72 def shutdown(self): 74 def shutdown(self):
73 self.is_running = False 75 self.is_running = False
74 return 1 76 return 1
75 77
76 78
77 # "Safely" split a string at |sep| into a [key, value] pair. If |sep| does not 79 # "Safely" split a string at |sep| into a [key, value] pair. If |sep| does not
78 # exist in |str|, then the entire |str| is the key and the value is set to an 80 # exist in |str|, then the entire |str| is the key and the value is set to an
79 # empty string. 81 # empty string.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 parser.print_help() 205 parser.print_help()
204 elif len(args) == 2: 206 elif len(args) == 2:
205 Run((SERVER_HOST, int(args[1]))) 207 Run((SERVER_HOST, int(args[1])))
206 else: 208 else:
207 Run((SERVER_HOST, SERVER_PORT)) 209 Run((SERVER_HOST, SERVER_PORT))
208 return 0 210 return 0
209 211
210 212
211 if __name__ == '__main__': 213 if __name__ == '__main__':
212 sys.exit(main()) 214 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698