Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: cms/bin/test_server.py

Issue 29327611: Issue 3056 - [cms] Enable threading for the test server (Closed)
Patch Set: Use daemon threads Created Sept. 15, 2015, 3:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« 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 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 if __name__ == "__main__": 117 if __name__ == "__main__":
118 if len(sys.argv) < 2: 118 if len(sys.argv) < 2:
119 source = FileSource(os.curdir) 119 source = FileSource(os.curdir)
120 elif os.path.isdir(sys.argv[1]): 120 elif os.path.isdir(sys.argv[1]):
121 source = FileSource(sys.argv[1]) 121 source = FileSource(sys.argv[1])
122 else: 122 else:
123 sys.exit("Usage: %s [source_dir]" % sys.argv[0]) 123 sys.exit("Usage: %s [source_dir]" % sys.argv[0])
124 124
125 try: 125 try:
126 from werkzeug.serving import run_simple 126 from werkzeug.serving import ThreadedWSGIServer, run_simple
127
128 ThreadedWSGIServer.daemon_threads = True
129
127 def run(*args, **kwargs): 130 def run(*args, **kwargs):
128 # The werkzeug logger must be configured before the 131 # The werkzeug logger must be configured before the
129 # root logger. Also we must prevent it from propagating 132 # root logger. Also we must prevent it from propagating
130 # messages, otherwise messages are logged twice. 133 # messages, otherwise messages are logged twice.
131 import logging 134 import logging
132 logger = logging.getLogger("werkzeug") 135 logger = logging.getLogger("werkzeug")
133 logger.propagate = False 136 logger.propagate = False
134 logger.setLevel(logging.INFO) 137 logger.setLevel(logging.INFO)
135 logger.addHandler(logging.StreamHandler()) 138 logger.addHandler(logging.StreamHandler())
136 139
137 run_simple(*args, **kwargs) 140 run_simple(threaded=True, *args, **kwargs)
138 except ImportError: 141 except ImportError:
139 from wsgiref.simple_server import make_server 142 from SocketServer import ThreadingMixIn
143 from wsgiref.simple_server import WSGIServer, make_server
144
145 class ThreadedWSGIServer(ThreadingMixIn, WSGIServer):
146 daemon_threads = True
147
140 def run(host, port, app, **kwargs): 148 def run(host, port, app, **kwargs):
141 def wrapper(environ, start_response): 149 def wrapper(environ, start_response):
142 try: 150 try:
143 return app(environ, start_response) 151 return app(environ, start_response)
144 except Exception, e: 152 except Exception, e:
145 return show_error(start_response, "500 Internal Server Error", 153 return show_error(start_response, "500 Internal Server Error",
146 uri=environ.get("PATH_INFO"), error=e) 154 uri=environ.get("PATH_INFO"), error=e)
147 155
148 server = make_server(host, port, wrapper) 156 server = make_server(host, port, wrapper, ThreadedWSGIServer)
149 print " * Running on http://%s:%i/" % server.server_address 157 print " * Running on http://%s:%i/" % server.server_address
150 server.serve_forever() 158 server.serve_forever()
151 159
152 run("localhost", 5000, handler, use_reloader=True, use_debugger=True) 160 run("localhost", 5000, handler, use_reloader=True, use_debugger=True)
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