Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 96a01efc48bd
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 542e047f5aeb
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Feb 8, 2015

  1. Copy the full SHA
    abb7d9f View commit details
  2. Copy the full SHA
    a50c745 View commit details
  3. ctlmgr: clean shutdown

    sbourdeauducq committed Feb 8, 2015
    Copy the full SHA
    542e047 View commit details
Showing with 28 additions and 6 deletions.
  1. +28 −6 artiq/frontend/artiq_ctlmgr.py
34 changes: 28 additions & 6 deletions artiq/frontend/artiq_ctlmgr.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
import os
import logging
import signal
import shlex

from artiq.protocols.sync_struct import Subscriber
from artiq.tools import verbosity_args, init_logger
@@ -47,9 +48,14 @@ def launcher(self, name, command, retry):
while True:
logger.info("Starting controller %s with command: %s",
name, command)
process = yield from asyncio.create_subprocess_exec(*command.split())
yield from asyncio.shield(process.wait())
logger.warning("Controller %s exited", name)
try:
process = yield from asyncio.create_subprocess_exec(
*shlex.split(command))
yield from asyncio.shield(process.wait())
except FileNotFoundError:
logger.warning("Controller %s failed to start", name)
else:
logger.warning("Controller %s exited", name)
logger.warning("Restarting in %.1f seconds", retry)
yield from asyncio.sleep(retry)
except asyncio.CancelledError:
@@ -107,6 +113,12 @@ def delete_all(self):
for name in set(self.active_or_queued):
del self[name]

@asyncio.coroutine
def shutdown(self):
self.process_task.cancel()
for c in self.active.values():
yield from c.end()


class ControllerDB:
def __init__(self, retry_command):
@@ -147,21 +159,31 @@ def set_host_filter():
logger.warning("Connection to master lost")
logger.warning("Retrying in %.1f seconds", retry_master)
yield from asyncio.sleep(retry_master)
except asyncio.CancelledError:
pass
finally:
controller_db.current_controllers.delete_all()
yield from controller_db.current_controllers.shutdown()


def main():
args = get_argparser().parse_args()
init_logger(args)

if os.name == "nt":
loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(loop)
else:
loop = asyncio.get_event_loop()

try:
loop.run_until_complete(ctlmgr(args.server, args.port,
args.retry_master, args.retry_command))
task = asyncio.Task(ctlmgr(
args.server, args.port, args.retry_master, args.retry_command))
try:
loop.run_forever()
finally:
task.cancel()
loop.run_until_complete(asyncio.wait_for(task, None))

finally:
loop.close()