Skip to content

Commit 3129216

Browse files
committed
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?
1 parent b4ae44d commit 3129216

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

planemo/galaxy/serve.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ def _serve(ctx, runnables, **kwds):
4949
if port is None:
5050
port = network_util.get_free_port()
5151

52+
timeout = 500
53+
galaxy_url = "http://%s:%s" % (host, port)
5254
ctx.vlog("Waiting for service on (%s, %s)" % (host, port))
53-
assert network_util.wait_net_service(host, port)
55+
assert network_util.wait_http_service(galaxy_url, timeout=timeout)
5456
time.sleep(.1)
5557
ctx.vlog("Waiting for service on (%s, %s)" % (host, port))
56-
assert network_util.wait_net_service(host, port)
58+
assert network_util.wait_http_service(galaxy_url)
5759
time.sleep(5)
5860
ctx.vlog("Waiting for service on (%s, %s)" % (host, port))
59-
assert network_util.wait_net_service(host, port)
61+
assert network_util.wait_http_service(galaxy_url)
6062
config.install_workflows()
6163
return config
6264

planemo/network_util.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import socket
22
from time import time as now
33

4+
from six.moves.urllib.error import URLError
5+
from six.moves.urllib.request import urlopen
6+
47

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

1215

16+
def wait_http_service(url, timeout=None):
17+
if timeout:
18+
end = now() + timeout
19+
20+
while True:
21+
try:
22+
if timeout:
23+
next_timeout = end - now()
24+
if next_timeout < 0:
25+
return False
26+
27+
kwds = {} if timeout is None else dict(timeout=next_timeout)
28+
urlopen(url, **kwds)
29+
return True
30+
except URLError:
31+
pass
32+
33+
1334
# code.activestate.com/recipes/576655-wait-for-network-service-to-appear
1435
def wait_net_service(server, port, timeout=None):
1536
""" Wait for network service to appear

0 commit comments

Comments
 (0)