Skip to content

Commit

Permalink
Merge pull request #20 from w3c/jgraham/stash
Browse files Browse the repository at this point in the history
Use shared stash as a context manager.
  • Loading branch information
jgraham committed Jul 13, 2015
2 parents 04dea96 + 1b70a06 commit 9db27c1
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions serve/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,6 @@ def get_ssl_config(config, external_domains, ssl_environment):
"cert_path": cert_path,
"encrypt_after_connect": config["ssl"]["encrypt_after_connect"]}

def start_stash_server(host, port, authkey):
stash.start_server(address=(host, port), authkey=authkey)
stash.store_env_config((host, port, authkey))

def start(config, ssl_environment, routes, **kwargs):
host = config["host"]
domains = get_subdomains(host)
Expand All @@ -374,9 +370,6 @@ def start(config, ssl_environment, routes, **kwargs):

ssl_config = get_ssl_config(config, external_config["domains"].values(), ssl_environment)

# The stash server for all other servers to use.
start_stash_server(host, port=get_port(), authkey=str(uuid.uuid4()))

if config["check_subdomains"]:
check_subdomains(host, paths, bind_hostname, ssl_config)

Expand Down Expand Up @@ -492,12 +485,13 @@ def main():

setup_logger(config["log_level"])

with get_ssl_environment(config) as ssl_env:
config_, servers = start(config, ssl_env, default_routes(), **kwargs)
with stash.StashServer((config["host"], get_port()), authkey=str(uuid.uuid4())):
with get_ssl_environment(config) as ssl_env:
config_, servers = start(config, ssl_env, default_routes(), **kwargs)

try:
while any(item.is_alive() for item in iter_procs(servers)):
for item in iter_procs(servers):
item.join(1)
except KeyboardInterrupt:
logger.info("Shutting down")
try:
while any(item.is_alive() for item in iter_procs(servers)):
for item in iter_procs(servers):
item.join(1)
except KeyboardInterrupt:
logger.info("Shutting down")

0 comments on commit 9db27c1

Please sign in to comment.