Monitor hangs on context manager exit
agronholm opened this issue · 5 comments
While fixing issue #162 solved the problem of starting the monitor in an already running loop, it has difficulties shutting down because it first schedules a future to be run on the loop but waits on that future on that loop's own thread, so the loop never has a chance to complete the task.
Yeah, I suspected that my clean up logic was not good.
Issue in async python REPL server, we expose it on separate port so user can directly connect and bypass regular aiomonitor. It is hard to make proper clean up here. One solution is disable this bypassing feature and start and stop server on demand.
are you calling close()
method inside coroutine?
This is the complete module in which I start and stop aiomonitor:
from aiomonitor import Monitor, MONITOR_PORT, CONSOLE_PORT
from asphalt.core import Component, Context, context_teardown
class AIOMonitorComponent(Component):
def __init__(self, host: str = '0.0.0.0', port: int = MONITOR_PORT,
console_port: int = CONSOLE_PORT, console_enabled: bool = True) -> None:
self.host = host
self.port = port
self.console_port = console_port
self.console_enabled = console_enabled
@context_teardown
async def start(self, ctx: Context):
with Monitor(ctx.loop, host=self.host, port=self.port, console_port=self.console_port,
console_enabled=self.console_enabled):
yield
On aiomonitor 0.3.1, this works fine.
0.3.1 did not close resources correctly as results tests were unstable... I never designed monitor to start inside coroutine. I think there should be separate API for async mode.