本文整理汇总了Python中six.moves.BaseHTTPServer.HTTPServer.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPServer.shutdown方法的具体用法?Python HTTPServer.shutdown怎么用?Python HTTPServer.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.BaseHTTPServer.HTTPServer
的用法示例。
在下文中一共展示了HTTPServer.shutdown方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: oauth_server
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import shutdown [as 别名]
def oauth_server():
# Start the OAuth server on a random port in the background
server = HTTPServer(('', 0), OAuthHandler)
server.url = 'http://{0}:{1}/'.format(*server.server_address)
thread = threading.Thread(target=server.serve_forever)
thread.start()
try:
yield server
finally:
server.shutdown()
thread.join()
server.server_close()
示例2: run
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import shutdown [as 别名]
def run(self):
"""
Runs the server using Python's simple HTTPServer.
TODO: make this multithreaded.
"""
httpd = HTTPServer((self.host, self.port), self._Handler)
sa = httpd.socket.getsockname()
serve_message = "Serving HTTP on {host} port {port} (http://{host}:{port}/) ..."
print(serve_message.format(host=sa[0], port=sa[1]))
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\nKeyboard interrupt received, exiting.")
httpd.shutdown()
示例3: test
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import shutdown [as 别名]
def test():
host = 'localhost'
# When I use port 0 here, it works for the first fetch and the
# next one gets connection refused. Bummer. So instead, pick a
# port that's *probably* not in use.
import os
port = (os.getpid() % 31000) + 1024
server = HTTPServer((host, port), FetcherTestHandler)
import threading
server_thread = threading.Thread(target=server.serve_forever)
server_thread.setDaemon(True)
server_thread.start()
run_fetcher_tests(server)
server.shutdown()
示例4: _zero_instance_app_through_http
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import shutdown [as 别名]
def _zero_instance_app_through_http():
class JSONRequestHandler (BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(open(
'tests/data/marathon/apps/zero_instance_sleep.json',
'rb').read())
host = 'localhost'
port = 12345
server = HTTPServer((host, port), JSONRequestHandler)
thread = threading.Thread(target=server.serve_forever)
thread.setDaemon(True)
thread.start()
with app('http://{}:{}'.format(host, port), 'zero-instance-app'):
try:
yield
finally:
server.shutdown()
示例5: import
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import shutdown [as 别名]
__test__ = False
if __name__ == '__main__':
import eventlet
eventlet.monkey_patch()
from six.moves.BaseHTTPServer import (
HTTPServer,
BaseHTTPRequestHandler,
)
import threading
server = HTTPServer(('localhost', 0), BaseHTTPRequestHandler)
thread = threading.Thread(target=server.serve_forever)
# Before fixing it the code would never go pass this line because:
# * socketserver.BaseServer that's used behind the scenes here uses
# selectors.PollSelector if it's available and we don't have green poll
# implementation so this just couldn't work
# * making socketserver use selectors.SelectSelector wasn't enough as
# until now we just failed to monkey patch selectors module
#
# Due to the issues above this thread.start() call effectively behaved
# like calling server.serve_forever() directly in the current thread
#
# Original report: https://github.com/eventlet/eventlet/issues/249
thread.start()
server.shutdown()
print('pass')
示例6: mirror_server
# 需要导入模块: from six.moves.BaseHTTPServer import HTTPServer [as 别名]
# 或者: from six.moves.BaseHTTPServer.HTTPServer import shutdown [as 别名]
def mirror_server(mirrors_dict):
mirror_file_path = '/mirrors.json'
mirror_corrupt_file_path = '/corrupt_mirrors.json'
mirror_json_varname = 'ci_repos'
mirror_data = {mirror_json_varname: mirrors_dict}
mirror_json = json.dumps(mirror_data).encode('utf8')
class MirrorRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == mirror_file_path:
self.send_response(200)
self.send_header("Content-type", 'application/json')
self.end_headers()
self.wfile.write(mirror_json)
elif self.path == mirror_corrupt_file_path:
self.send_response(200)
self.send_header("Content-type", 'application/json')
self.end_headers()
self.wfile.write('{"this": "is", "bad": "json"')
else:
self.send_error(404)
for attempt in range(0,20):
server_address = ('127.0.0.1', randrange(8765, 8876))
try:
server = HTTPServer(server_address, MirrorRequestHandler)
except socket.error as e:
if e.errno == 98:
continue
raise
break
else:
raise RuntimeError("Failed to allocate port for mirror_server fixture")
server_url = 'http://{0}:{1}'.format(*server_address)
sthread = Thread(target=server.serve_forever)
sthread.start()
try:
# Wait for http server to start
sleep(0.1)
# ensure we won't implictly try to use proxies to access local server
old_env = dict((
(k, environ.pop(k))
for k in ('http_proxy', 'HTTP_PROXY') if k in environ
))
try:
yield dict(
mirror_url=urljoin(server_url, mirror_file_path),
json_varname=mirror_json_varname,
bad_path_url=urljoin(server_url, '/bad_file'),
bad_port_url=urljoin(
'http://{0}:8764'.format(server_address[0]),
mirror_file_path
),
corrupt_url=urljoin(server_url, mirror_corrupt_file_path),
)
finally:
environ.update(old_env)
finally:
server.shutdown()
sthread.join()