#!/home/mrocklin/Software/anaconda/envs/py34/bin/python

from sys import argv
if len(argv) == 2:
    if ':' in argv[1]:
        ip, port = argv[1].split(':')
    else:
        ip = None
        port = argv[1]
else:
    ip = None
    port = 8787

from distributed.utils import get_ip
ip = get_ip()

port = int(port)

# Set up signal handling
import signal

def handle_signal(sig, frame):
    IOLoop.instance().add_callback(IOLoop.instance().stop)

signal.signal(signal.SIGINT, handle_signal)
signal.signal(signal.SIGTERM, handle_signal)


# Run stuff
from distributed import Center
from tornado.ioloop import IOLoop
print("Start center at %s:%d" % (ip, port))
center = Center(ip, port)
center.listen(port)
IOLoop.current().start()
IOLoop.current().close()
print("End center at %s:%d" % (ip, port))
