2

Using Arch Linux everytime I try to use Python interactive mode no matter what I type I get Segmentation fault (core dumped) and the Python interpreter exits.

I do not have any problem running Python scripts or doing something like:

$ echo "print(1+1)" | python

But when I enter interactive mode, whether it is with python or python2, as soon as I type any command and press enter, the interpreter halts and then if I press enter again (or any other key) I get the message Segmentation fault (core dumped) and the interpreter exits.

I test installing bpython and I have no problem or errors with this interface for the python interpreter.

I tried gdb and when I type run at the gdb prompt I had to press enter twice (when hit enter once it just halted) and then got:

Starting program: /usr/bin/python
Segmentation fault (core dumped)

and gdb exits.

Maybe this information is useful:

$ which python
/usr/bin/python

$ which python2
/usr/bin/python2

$ python --version
Python 3.6.1

$ python2 --version
Python 2.7.13

$ uname -a
Linux archimiro 4.11.6-3-ARCH #1 SMP PREEMPT Thu Jun 22 12:21:46 CEST 2017 x86_64 GNU/Linux

migrated from serverfault.com Jun 26 '17 at 21:38

This question came from our site for system and network administrators.

  • 1
    Can you run it under gdb and perhaps get a bt ? – thrig Jun 26 '17 at 21:56
  • @thrig Thanks! I would love to do that but I'm not sure how. I read about that when I searched for my problem and ran gdb python and got (gdb), but was not sure what to do after that, so I tried typing a python command and then bt and got No stack, and then came here :). – archemiro Jun 26 '17 at 22:02
  • 1
    run at the gdb prompt should start python and dump you into interactive mode. – thrig Jun 26 '17 at 22:09
  • 1
    You might get a clue from strace python, compared with the non-interactive version. – meuh Jun 27 '17 at 14:29
  • 1
    I think it would be much better if you post the answer, especially if you manage to find what lines are causing the problem, as I'm sure other people are likely to see the same bug. – meuh Jun 27 '17 at 17:33
2

Following meuh suggestion I ran Python with strace and look at the differences between interactive and non-interactive Python.

Interactive Python read my ~/.inputrc as it uses readline, and this was the file that was causing the Segmentation fault (core dumped).

I had an ~/.inputrc which came from another machine (Ubuntu) and inside of it I had blindly copied the contents of (Ubuntu) /usr/share/doc/bash/inputrc.arrows.

The content of /usr/share/doc/bash/inputrc.arrows is:

# This file controls the behaviour of line input editing for
# programs that use the Gnu Readline library.
#
# Arrow keys in keypad mode
#
"\C-[OD"        backward-char
"\C-[OC"        forward-char
"\C-[OA"        previous-history
"\C-[OB"        next-history
#
# Arrow keys in ANSI mode
#
"\C-[[D"        backward-char
"\C-[[C"        forward-char
"\C-[[A"        previous-history
"\C-[[B"        next-history
#
# Arrow keys in 8 bit keypad mode
#
"\C-M-OD"       backward-char
"\C-M-OC"       forward-char
"\C-M-OA"       previous-history
"\C-M-OB"       next-history
#
# Arrow keys in 8 bit ANSI mode
#
"\C-M-[D"       backward-char
"\C-M-[C"       forward-char
"\C-M-[A"       previous-history
"\C-M-[B"       next-history

The 8 bit keypad mode and the 8 bit ANSI mode were the specific cause of the problem so after removing them everything works fine.

Thanks to thrig for pointing me to gdb and being patient enough as I had never used that tool before. The same with meuh who suggested using strace which was also new to me. I had no idea where to start debugging as I am just a casual user who enjoys learning new things. Great community!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.