Permalink
Browse files

Rework Galaxy serve to wait using urllib instead of sockets.

That wait_for_net_service simply wasn't working with Mac OS X - at least in my hands. Maybe some difference with socket handling between BSD and Linux?
  • Loading branch information...
jmchilton committed Mar 16, 2017
1 parent b4ae44d commit 312921650b0f9a4e2957a48fe974da50694db074
Showing with 26 additions and 3 deletions.
  1. +5 −3 planemo/galaxy/serve.py
  2. +21 −0 planemo/network_util.py
@@ -49,14 +49,16 @@ def _serve(ctx, runnables, **kwds):
if port is None:
port = network_util.get_free_port()

timeout = 500
galaxy_url = "http://%s:%s" % (host, port)
ctx.vlog("Waiting for service on (%s, %s)" % (host, port))
assert network_util.wait_net_service(host, port)
assert network_util.wait_http_service(galaxy_url, timeout=timeout)
time.sleep(.1)
ctx.vlog("Waiting for service on (%s, %s)" % (host, port))
assert network_util.wait_net_service(host, port)
assert network_util.wait_http_service(galaxy_url)
time.sleep(5)
ctx.vlog("Waiting for service on (%s, %s)" % (host, port))
assert network_util.wait_net_service(host, port)
assert network_util.wait_http_service(galaxy_url)
config.install_workflows()
return config

@@ -1,6 +1,9 @@
import socket
from time import time as now

from six.moves.urllib.error import URLError
from six.moves.urllib.request import urlopen


def get_free_port():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -10,6 +13,24 @@ def get_free_port():
return port


def wait_http_service(url, timeout=None):
if timeout:
end = now() + timeout

while True:
try:
if timeout:
next_timeout = end - now()
if next_timeout < 0:
return False

kwds = {} if timeout is None else dict(timeout=next_timeout)
urlopen(url, **kwds)
return True
except URLError:
pass


# code.activestate.com/recipes/576655-wait-for-network-service-to-appear
def wait_net_service(server, port, timeout=None):
""" Wait for network service to appear

0 comments on commit 3129216

Please sign in to comment.