You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by nk...@apache.org on 2019/07/23 09:44:35 UTC
[avro] branch master updated: AVRO-2445: Remove StoppableHTTPServer
Polyfill (#567)
This is an automated email from the ASF dual-hosted git repository.
nkollar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new efe1181 AVRO-2445: Remove StoppableHTTPServer Polyfill (#567)
efe1181 is described below
commit efe1181bc76adc89a69f0763ad469386db84ed67
Author: Michael A. Smith <mi...@syapse.com>
AuthorDate: Tue Jul 23 05:44:29 2019 -0400
AVRO-2445: Remove StoppableHTTPServer Polyfill (#567)
---
lang/py/src/avro/tool.py | 25 ++++++-------------------
1 file changed, 6 insertions(+), 19 deletions(-)
diff --git a/lang/py/src/avro/tool.py b/lang/py/src/avro/tool.py
index 66b341c..6a92fee 100644
--- a/lang/py/src/avro/tool.py
+++ b/lang/py/src/avro/tool.py
@@ -19,7 +19,9 @@ Command-line tool
NOTE: The API for the command-line tool is experimental.
"""
+
import sys
+import threading
import urlparse
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
@@ -54,24 +56,9 @@ class GenericHandler(BaseHTTPRequestHandler):
resp_writer.write_framed_message(resp_body)
if server_should_shutdown:
print >> sys.stderr, "Shutting down server."
- self.server.force_stop()
-
-class StoppableHTTPServer(HTTPServer):
- """HTTPServer.shutdown added in Python 2.6. FML."""
- stopped = False
- allow_reuse_address = True
- def __init__(self, *args, **kw):
- HTTPServer.__init__(self, *args, **kw)
- self.allow_reuse_address = True
-
- def serve_forever(self):
- while not self.stopped:
- self.handle_request()
-
- def force_stop(self):
- self.server_close()
- self.stopped = True
- self.serve_forever()
+ quitter = threading.Thread(target=self.server.shutdown)
+ quitter.daemon = True
+ quitter.start()
def run_server(uri, proto, msg, datum):
url_obj = urlparse.urlparse(uri)
@@ -80,7 +67,7 @@ def run_server(uri, proto, msg, datum):
global server_should_shutdown
server_should_shutdown = False
responder = GenericResponder(proto, msg, datum)
- server = StoppableHTTPServer(server_addr, GenericHandler)
+ server = HTTPServer(server_addr, GenericHandler)
print "Port: %s" % server.server_port
sys.stdout.flush()
server.allow_reuse_address = True