示例#1
0
def start(device, dashboard=None, data_dir=None, rotate=None, channel=None,
        replay=None):

    topic = n23.Topic()
    if dashboard:
        create_app(topic, dashboard)

    files = None
    if data_dir:
        files = n23.data_logger_file('mocto', data_dir)

    w = n23.cycle(
        rotate, workflow, topic, device, files=files, channel=channel,
        replay=replay
    )
    loop = asyncio.get_event_loop()
    loop.run_until_complete(w)
示例#2
0
文件: core.py 项目: wrobell/dshrub
def start(device, sensors, dashboard=None, data_dir=None, rotate=None,
        channel=None, replay=None):

    dbus_loop = None
    topic = n23.Topic()

    if dashboard:
        cache = Cache(sensors)
        # read_data(preload_file, sensors, N_DATA, cache)
        ws.create_app(sensors, topic, cache, dashboard)
    else:
        cache = None

    if replay:
        logger.info('replaying a data file {}'.format(replay))
        replay = h5py.File(replay)
    else:
        import dbus
        import threading
        from dbus.mainloop.glib import DBusGMainLoop
        from gi.repository import GObject
        dbus_loop = DBusGMainLoop(set_as_default=True)
        dbus_main_loop = GObject.MainLoop()
        dbus_bus = dbus.SystemBus(mainloop=dbus_loop)
        thread = threading.Thread(target=dbus_main_loop.run, daemon=True)
        thread.start()

    files = None
    if data_dir:
        files = n23.dlog_filename('dshrub', data_dir)

    w = n23.cycle(
        rotate, workflow, topic, device, sensors, files=files,
        channel=channel, replay=replay, cache=cache, dbus_bus=dbus_bus
    )
    loop = asyncio.get_event_loop()
    loop.add_signal_handler(signal.SIGTERM, sys.exit)
    try:
        loop.run_until_complete(w)
    finally:
        loop.remove_signal_handler(signal.SIGTERM)
        w.close()