Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctrl-x not function to leave console #166

Closed
ghost opened this issue Jan 6, 2016 · 58 comments · Fixed by #236 or #350
Closed

Ctrl-x not function to leave console #166

ghost opened this issue Jan 6, 2016 · 58 comments · Fixed by #236 or #350

Comments

@ghost
Copy link

ghost commented Jan 6, 2016

When attempting to make local calls in the console, pressing ctrl-x merely prints ^x rather than leaving the console. At this point, the only way out is to kill pudb. An interesting behavior is that this only happens after issuing a command in the console; ctrl-x works fine until then.

Details:
pudb version: 2015.4.1
installed with pip
running in osx 10.11.2 in iTerm2, Terminal, and Neovim's terminal mode

@inducer
Copy link
Owner

inducer commented Jan 6, 2016

I can't reproduce this, so this likely has something to do with your setup. On Linux, with vte (gnome terminal), konsole, and xterm, this works just fine for me.

Can you try through both display drivers (raw/curses) in the pref screen and see if that helps?

@ghost
Copy link
Author

ghost commented Jan 6, 2016

Changing to curses seems to have fixed it. Thanks.

@nedbat
Copy link
Contributor

nedbat commented Jun 10, 2016

I have the same reported behavior on Mac. I am using iTerm2.
^X gets me into the console, and another ^X will get me out of it. But if I type '1' to see the value 1 in the console, then ^X just echoes ^X, and I can't figure out a way to do anything but kill pudb.

@nedbat
Copy link
Contributor

nedbat commented Jun 10, 2016

Switching to curses doesn't improve the console, and makes other things bad :(

@inducer
Copy link
Owner

inducer commented Jun 10, 2016

^X used to have some flow control behavior. Can you turn that off in iTerm2?

@inducer
Copy link
Owner

inducer commented Jun 10, 2016

(I think. Actually not 100% sure about that.)

@nedbat
Copy link
Contributor

nedbat commented Jun 10, 2016

That doesn't sound right to me. The first ^X would have that effect then, but it doesn't. And the second ^X doesn't stop the flow, it just echoes ^X, and you can still type into the console window.

@inducer
Copy link
Owner

inducer commented Jun 10, 2016

@asmeurer, you use (used?) iTerm2, I recall. Any clues?

@asmeurer
Copy link
Collaborator

It is working for me, but I am using the iTerm2 nightly build. But it also works for me in Terminal.app. What version of urwid are you guys using? I have 1.3.1.

@nedbat
Copy link
Contributor

nedbat commented Jun 10, 2016

Full freeze output (only some of which is for pudb):

-e hg+ssh://[email protected]/ned/coveragepy@f4001cd0cd5210e67ba8ba2e15c9bc362a001e2e#egg=coverage
covtestegg1==0.0.0
decorator==4.0.9
eventlet==0.19.0
gevent==1.1.1
greenlet==0.4.9
mock==2.0.0
nose==1.3.7
pbr==1.10.0
pudb==2016.2
PyContracts==1.7.9
Pygments==2.1.3
pyparsing==2.1.4
six==1.10.0
unittest-mixins==1.0
urwid==1.3.1

@nedbat
Copy link
Contributor

nedbat commented Jun 10, 2016

BTW, I tested using the Mac Terminal app also, and it behaves the same for me as in iTerm2.

@asmeurer
Copy link
Collaborator

Yeah me too, that is, it works in both.

In fact, I just tried using the guest user account on my Mac to install pudb fresh, using Terminal.app, so that everything is default settings, and I still can't reproduce this. Any guesses as to what might be causing it. I also tried fiddling with different $TERM settings, but it doesn't seem to matter.

@inducer
Copy link
Owner

inducer commented Jun 10, 2016

@nedbat, whats your $TERM?

@nedbat
Copy link
Contributor

nedbat commented Jun 10, 2016

xterm-256color

@inducer
Copy link
Owner

inducer commented Jun 10, 2016

Is that what you have, @asmeurer?

@asmeurer
Copy link
Collaborator

Yeah, and I tried all the other ones in the Terminal settings in my guest account. Haven't yet found any configuration that reproduces this.

@nedbat
Copy link
Contributor

nedbat commented Jun 11, 2016

If you've got some suggestion for where in the pudb code to add some debugging information extraction, I'm game to give it a try.

@mlubimow
Copy link
Contributor

@asmeurer Yes but shell.py is lazy loaded, after its loaded problem is gone but its quite annoying to open shell every time user wants to debug something.

@asmeurer
Copy link
Collaborator

According to #191, importing readline at the top of debugger.py fixes the issue.

When I start pudb and go straight to the console and type

import sys
sys.modules['readline']

it's there, meaning it's already been imported. Is it the same for you?

@asmeurer
Copy link
Collaborator

OK, it seems that shell.py is run as soon as you run any command (above, running import sys runs it, which imports readline). Even so, I can't get this to reproduce before readline is ever imported (as verified by running the above as a script with pudb).

@mlubimow
Copy link
Contributor

mlubimow commented Jun 28, 2016

I don't have this issue on another machine as well, this is happening only on this system (El Capitan 10.11.5). Im not familiar with this project but maybe when readline is imported, other library (urwid? subprocess?) uses this library to read line instead of something else and this is why it works?
Hard to say for me.

Surely if we try to read line from console even once before library gets imported, screen gets corrupted.

@nedbat
Copy link
Contributor

nedbat commented Feb 9, 2017

I just noticed that this problem seems to be fixed now? I have iTerm2 v3.0.12

@inducer
Copy link
Owner

inducer commented Feb 9, 2017

Thanks for the update. It doesn't feel like we meaningfully got to the bottom of what was causing this--but I'm glad to hear it's no longer occurring for you. It'd be tempting to just blame it on some external circumstance and move on, but I'm not sure I'm confident it won't rear its head again at some point.

Let's just leave this open for now.

@gopar
Copy link

gopar commented Feb 24, 2017

Having the same issue.

$TERM: xterm-256color
Pudb: 2016.2
Mac: 10.12.3

Using GNU Screen (Problem still happens with GNU Screen off)
Using default Mac terminal app
Installed via pip

Just tried iTerm 3.0.14. Still has the bug

@asmeurer
Copy link
Collaborator

Didn't think of this before, but maybe the version of readline has something to do with it. What does this give you (may not work if you don't have the developer tools installed)?

import readline
import subprocess
subprocess.call(["otool", "-L", readline._rl.__file__])

@asmeurer
Copy link
Collaborator

If that gives an error about no attribute '_rl' use

import readline
import subprocess
subprocess.call(["otool", "-L", readline.__file__])

@nedbat
Copy link
Contributor

nedbat commented Feb 25, 2017

Ctrl-X works for me currently, and here's my readline data point:

>>> import readline
>>> import subprocess
>>> subprocess.call(["otool", "-L", readline._rl.__file__])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '_rl'
>>> subprocess.call(["otool", "-L", readline.__file__])
/usr/local/virtualenvs/stell/lib/python2.7/lib-dynload/readline.so:
	/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
	/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
0
>>>

@gopar
Copy link

gopar commented Feb 26, 2017

Here's the output

Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>> import subprocess
>>> subprocess.call(['otool', '-L', readline._rl.__file__])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '_rl'
>>> subprocess.call(['otool', '-L', readline.__file__])
/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so:
        /usr/local/opt/readline/lib/libreadline.7.dylib (compatibility version 7.0.0, current version 7.0.0)
        /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
0
>>> 

@gopar
Copy link

gopar commented Mar 2, 2017

Not sure if it makes any difference but here's they py3 output. I don't have any issues using this with pudb. Any other thing I should try to get pudb working again in py2? Don't like using other debuggers beside this one \o/

Python 3.6.0 (default, Dec 24 2016, 08:01:42) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>> import subprocess
>>> subprocess.call(["otool", "-L", readline._rl.__file__])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'readline' has no attribute '_rl'
>>> subprocess.call(["otool", "-L", readline.__file__])
/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload/readline.cpython-36m-darwin.so:
        /usr/local/opt/readline/lib/libreadline.7.dylib (compatibility version 7.0.0, current version 7.0.0)
        /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
0
>>> 

@matiasbastos
Copy link

matiasbastos commented Dec 3, 2018

Sorry but still having this issue :(. It gets solved doing what @asmeurer said (#166 (comment)). Im on py 2.7.10, pudb 2018.1 and iTerm2 3.2.6.... I'm missing something?

asmeurer added a commit to asmeurer/PuDB that referenced this issue Mar 11, 2019
The issues with using a custom dict subclass to eval/exec are fixed in
Python 3. Without this, local functions in the shell cannot access global
variables (for instance, inside of list comprehentions).

See the discussion on issues inducer#166 and inducer#103.
asmeurer added a commit to asmeurer/PuDB that referenced this issue Mar 11, 2019
The issues with using a custom dict subclass to eval/exec are fixed in
Python 3. Without this, local functions in the shell cannot access global
variables (for instance, inside of list comprehensions).

See the discussion on issues inducer#166 and inducer#103.
@scirelli
Copy link

I'm still seeing this issue.

@asmeurer
Copy link
Collaborator

@scirelli what version of pudb and Python are you using?

@scirelli
Copy link

scirelli commented Jun 14, 2019

@scirelli what version of pudb and Python are you using?

pudb: 2019.1
Python: 3.7.3

@asmeurer
Copy link
Collaborator

Maybe my diagnosis of the source of the problem was incorrect. Which makes sense because it was never really clear to me how the globals() dict behavior could cause issues with urwid.

Can you give me more info about your system. What OS is it, and what Python are you using (system Python, python.org, anaconda...)? Also do the exact steps from #166 (comment) reproduce the issue for you?

@asmeurer asmeurer reopened this Jun 14, 2019
@scirelli
Copy link

Can you give me more info about your system. What OS is it, and what Python are you using (system Python, python.org, anaconda...)? Also do the exact steps from #166 (comment) reproduce the issue for you?

Mac, Python.org, just debugging using the cli python -m pudb <script>

All I have to do to reproduce is press <Ctrl+x>, try to execute a statement, then try to switch back to source with <Ctrl+x> again. It won't work and I'll start seeing control codes ^X etc. printed. They are printed outside of pudb. It's like pudb is not refreshing, typing enough characters and it'll scroll the previous text (pudb UI) up the screen. The only thing I can do is kill Python/pudb. I think if I hit enter enough times...not sure what causes it...but it'll try to execute everything I typed. I'll provide more info tomorrow, I'm not in front of that computer right now.

I was not having this problem a few weeks ago. I don't think this started happening until I updated to 2019.1. I was on 2018.1. I'll try to revert back to see what happens.

@scirelli
Copy link

scirelli commented Jun 14, 2019

@asmeurer
Recorded a video https://youtu.be/DZW94qwyrPE
macOS Mojova 10.14.5

Backspace wasn't working either.

I install pudb 2018.1 and it works fine. Looks like it's just something in the new version.

@asmeurer
Copy link
Collaborator

I'll check if I can reproduce this later (I need to install the python.org Python 3 on my Mac). It's also good to see that you are using a virtualenv. That may be relevant.

@scirelli
Copy link

I see it happening in 2018.1 when I hit the tab key to auto complete a variable name.

@asmeurer
Copy link
Collaborator

asmeurer commented Jul 9, 2019

I was able to reproduce this with the python.org Python 3 on my Mac.

I also got a traceback which sent me to post-mortem mode:

Traceback (most recent call last):
  File "/Users/aaronmeurer/Documents/pudb/pudb/__init__.py", line 152, in runscript
    dbg._runscript(mainpyfile)
  File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 468, in _runscript
    self.run(statement)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/bdb.py", line 585, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "test.py", line 3, in <module>
    import pudb
  File "test.py", line 3, in <module>
    import pudb
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/bdb.py", line 88, in
trace_dispatch
    return self.dispatch_line(frame)
  File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 189, in dispatch_line
    self.user_line(frame)
  File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 410, in user_line
    self.interaction(frame)
  File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 378, in interaction
    show_exc_dialog=show_exc_dialog)
  File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 2147, in call_with_ui
    return f(*args, **kwargs)
  File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 2400, in interaction
    self.event_loop()
  File "/Users/aaronmeurer/Documents/pudb/pudb/debugger.py", line 2360, in event_loop
    keys = self.screen.get_input()
  File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urwid/raw_display.py",
line 336, in get_input
    keys, raw = self.parse_input(None, None, self.get_available_raw_input())
  File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urwid/raw_display.py",
line 436, in get_available_raw_input
    codes = self._get_gpm_codes() + self._get_keyboard_codes()
  File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urwid/raw_display.py",
line 510, in _get_keyboard_codes
    code = self._getch_nodelay()
  File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urwid/raw_display.py",
line 644, in _getch_nodelay
    return self._getch(0)
  File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urwid/raw_display.py",
line 554, in _getch
    return ord(os.read(self._term_input_file.fileno(), 1))
TypeError: ord() expected a character, but string of length 0 found

(also annoyingly, the exception viewer did not have the option to save the traceback to a file)

@asmeurer
Copy link
Collaborator

asmeurer commented Jul 9, 2019

Bisected the problem, and unsurprisingly, this is the bad commit:

commit b0fc02060bee885a7846384a50a5a5c20d577d9f
Author: Aaron Meurer <[email protected]>
Date:   Mon Mar 11 16:29:25 2019 -0600

    Only avoid SetPropogatingDict in the builtin shell in Python 2

    The issues with using a custom dict subclass to eval/exec are fixed in
    Python 3. Without this, local functions in the shell cannot access global
    variables (for instance, inside of list comprehensions).

    See the discussion on issues #166 and #103.

So it seems my theory that this issue should only occur in Python 2 was wrong. There is something about the system Python that is at issue here, as it doesn't do it for me with the Anaconda Python.

@asmeurer
Copy link
Collaborator

asmeurer commented Jul 9, 2019

Maybe it has to do with the python.org Python (and also the system Python) using libedit instead of readline. Which means it could be related to #337.

@asmeurer
Copy link
Collaborator

asmeurer commented Jul 9, 2019

It's definitely readline. If I remove the readline imports in shell.py, the issue goes away. #337 doesn't fix it however.

asmeurer added a commit to asmeurer/PuDB that referenced this issue Jul 9, 2019
This fixes inducer#166. I have no idea why, but if readline is really libedit (like
for a system or python.org install on Mac), it causes the built in shell to
break the terminal inputs, but only when imported at the top level. If the
import is deferred, as far as I've seen, it doesn't happen.
@aseutin
Copy link

aseutin commented Nov 5, 2019

I'm having this same problem using the latest version of pudb and iterm2 on a Mac (I'm also using the curses shell in pudb). To reproduce the issue I just have to run pudb main.py, then hit ctrl-x or "!" to enter the python shell, then type some gibberish and click enter. Backspace stops working and ctrl-x appears in the prompt. It seems like ctrl-x does actually work (even though it doesn't appear to be working visually) because hitting ctrl-X then 'n' then will actually exit the shell and go to the next line as expected. Once the UI updates the issue will be fixed for the rest of the session and the shell works as expected

@golharam
Copy link

I'm just now running into this.
MacOS Mojava
Python 3.6.5

pudb was working fine for my under Python 2.7. I only noticed this when moving to Python 3. I"m using Terminal.app.

Other than that, I have nothing useful to contribute.

@asmeurer
Copy link
Collaborator

Can you check if #350 fixes the problem?

@golharam
Copy link

Yep, that fixed it

@JamoBox
Copy link

JamoBox commented Mar 31, 2020

@asmeurer I also ran into this issue using Python 3.8.0 and Kitty terminal on MacOS.

I've just tried out your patch and can confirm it fixes the issue for me.

@Xepe
Copy link

Xepe commented Nov 14, 2020

I am having the same issue, I can't exit from the command line using ctrl x after writing something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet