aio-libs / aiomonitor

aiomonitor is module that adds monitor and python REPL capabilities for asyncio application

Home Page:https://aiomonitor.aio-libs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Endless loop after exiting console

apatrushev opened this issue · comments

  1. Connect to remote server with socat/nc
  2. Run console command
  3. Exit from console with ctrl-d/cmd-d

See lots of messages:

monitor >>> Leaving monitor. Hit Ctrl-C to exit

Works on my macOS with iterm2/terminal, py3.6.2 and most recent master.

Just tested on my macOS 10.13.6/Python 3.7.0|3.7.0+|3.6.6|3.6.3/aiomonitor trunk/iTerm2 with following server code (if it matters):

import asyncio
import aiomonitor
from aiohttp import web

async def hello(request):
    return web.Response(text="Hello, world")

app = web.Application()
app.add_routes([web.get('/', hello)])

loop = asyncio.get_event_loop()
with aiomonitor.start_monitor(loop=loop):
    web.run_app(app)

and

socat - TCP4:localhost:50101

or

nc localhost 50101

What type of information I can provide to help you?

|tosha@local ~ $ socat - TCP4:localhost:50101

Asyncio Monitor: 1 tasks running
Type help for commands
monitor >>> console
Python 3.6.3 (default, Apr 21 2018, 12:04:52)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
---
This console is running in an asyncio event loop.
It allows you to wait for coroutines using the 'await' syntax.
Try: await asyncio.sleep(1, result=3)
---
>>> monitor >>> Leaving monitor. Hit Ctrl-C to exit
monitor >>> Leaving monitor. Hit Ctrl-C to exit
monitor >>> Leaving monitor. Hit Ctrl-C to exit
..... endless

I pressed CTRL-D after second >>>, just after entering the console.

Asyncio Monitor: 1 tasks running
Type help for commands
monitor >>> console
Python 3.6.2 (default, Jul 17 2017, 16:44:45)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
---
This console is running in an asyncio event loop.
It allows you to wait for coroutines using the 'await' syntax.
Try: await asyncio.sleep(1, result=3)
---
>>> ^D

in my case nothing happens... just "^D" printed on console

I suspect issue somewhere here:

sout.write('Type help for commands\n')
while not self._closing.is_set():
sout.write('monitor >>> ')
sout.flush()
try:
resp = sin.readline()
self._monitor_commans(sin, sout, resp)
except Exception as e:
sout.write('Bad command. %s\n' % e)
sout.flush()

You can put debugger in except block and may be see proper exception.

Ok, I will investigate myself what's happened with server and I will report here later this week.

I suspect that resp = sin.readline() always return None or something like that after ^D as result monitor tries to exit, but Exception on write/flush prevents full exiting.

Closing this issue fro now, feel free to reopen if you have more information.

Sorry for the long delay. I will try to describe a problem. Receiving empty line here (before strip) means EOF, but it is not processed properly:

https://github.com/aio-libs/aiomonitor/blob/master/aiomonitor/monitor.py#L167-L170

I do not know a better way to share issue. I created small screencast: https://asciinema.org/a/8bRjHNB0PQiB54fWfEgQthzAv

Closing this issue fro now, feel free to reopen if you have more information.

I have no rights to reopen issues.

I hope @jettify will find a time to review the PR

@apatrushev thanks for the fix! New version available on PyPI https://pypi.org/project/aiomonitor/0.4.5/