Esempio n. 1
0
class MonitorWire(WaitMixin, Wire):
    """

    .. wire:: harness.wires.aiomonitor.MonitorWire
      :type: output
      :runtime: python
      :config: harness.net.Server
      :requirements: aiomonitor

    """

    _monitor = None

    def configure(self, value: net_pb2.Server):
        assert isinstance(value, net_pb2.Server), type(value)

        from aiomonitor import Monitor, MONITOR_HOST, MONITOR_PORT

        self._monitor = Monitor(
            loop=asyncio.get_event_loop(),
            host=value.bind.host or MONITOR_HOST,
            port=value.bind.port or MONITOR_PORT,
        )

    async def __aenter__(self):
        self._monitor.start()

    async def __aexit__(self, exc_type, exc_val, exc_tb):
        self._monitor.close()
Esempio n. 2
0
    def configure(self, value: net_pb2.Server):
        assert isinstance(value, net_pb2.Server), type(value)

        from aiomonitor import Monitor, MONITOR_HOST, MONITOR_PORT

        self._monitor = Monitor(
            loop=asyncio.get_event_loop(),
            host=value.bind.host or MONITOR_HOST,
            port=value.bind.port or MONITOR_PORT,
        )
Esempio n. 3
0
def monitor(loop):
    def make_baz():
        return 'baz'
    locals_ = {'foo': 'bar', 'make_baz': make_baz}
    mon = Monitor(loop, locals=locals_)
    ev = threading.Event()

    def f(mon, loop, ev):
        asyncio.set_event_loop(loop)
        with mon:
            ev.set()
            loop.run_forever()

    thread = threading.Thread(target=f, args=(mon, loop, ev))
    thread.start()
    ev.wait()
    yield mon
    loop.call_soon_threadsafe(loop.stop)
    thread.join()
Esempio n. 4
0
def test_ctor(loop, unused_port):

    with Monitor(loop, console_enabled=False):
        loop.run_until_complete(asyncio.sleep(0.01, loop=loop))

    with start_monitor(loop, console_enabled=False) as m:
        loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
    assert m.closed

    m = Monitor(loop, console_enabled=False)
    m.start()
    try:
        loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
    finally:
        m.close()
        m.close()  # make sure call is idempotent
    assert m.closed

    m = Monitor(loop, console_enabled=False)
    m.start()
    with m:
        loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
    assert m.closed
Esempio n. 5
0
 async def f():
     with Monitor(loop, console_enabled=console_enabled):
         await asyncio.sleep(0.01, loop=loop)
Esempio n. 6
0
def test_ctor(loop, unused_port, console_enabled):

    with Monitor(loop, console_enabled=console_enabled):
        loop.run_until_complete(asyncio.sleep(0.01, loop=loop))

    with start_monitor(loop, console_enabled=console_enabled) as m:
        loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
    assert m.closed

    m = Monitor(loop, console_enabled=console_enabled)
    m.start()
    try:
        loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
    finally:
        m.close()
        m.close()  # make sure call is idempotent
    assert m.closed

    m = Monitor(loop, console_enabled=console_enabled)
    m.start()
    with m:
        loop.run_until_complete(asyncio.sleep(0.01, loop=loop))
    assert m.closed

    # make sure that monitor inside async func can exit correctly
    async def f():
        with Monitor(loop, console_enabled=console_enabled):
            await asyncio.sleep(0.01, loop=loop)

    loop.run_until_complete(f())