Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#12263 closed defect (fixed)

Unset TERM when running sage non-interactively

Reported by: jdemeyer Owned by: leif
Priority: major Milestone: sage-4.8
Component: scripts Keywords:
Cc: Merged in: sage-4.8.rc0
Authors: Jeroen Demeyer Reviewers: Volker Braun
Report Upstream: Workaround found; Bug reported upstream. Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by jdemeyer)

Because of either a readline or a Python bug, sometimes control characters are output by Python. For example, on my Gentoo Linux system:

jdemeyer@arcanis:~$ sage --python -c 'import readline' |cat -t
^[[?1034hjdemeyer@arcanis:~$

This breaks doctests at #12249 for sage-run. The easiest solution is to unset the TERM environment variable when running sage-run or sage-eval. This will effectively disable readline.

Upstream (readline): http://lists.gnu.org/archive/html/bug-readline/2007-08/msg00004.html

Apply 12263_unset_TERM.patch to the scripts repository.

Attachments (1)

12263_unset_TERM.patch (660 bytes) - added by jdemeyer 7 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 7 years ago by jdemeyer

  • Description modified (diff)
  • Report Upstream changed from N/A to Workaround found; Bug reported upstream.

Changed 7 years ago by jdemeyer

comment:2 Changed 7 years ago by jdemeyer

  • Description modified (diff)
  • Status changed from new to needs_review

comment:3 Changed 7 years ago by vbraun

  • Status changed from needs_review to positive_review

Looks good!

comment:4 Changed 7 years ago by jdemeyer

  • Merged in set to sage-4.8.rc0
  • Resolution set to fixed
  • Reviewers set to Volker Braun
  • Status changed from positive_review to closed

comment:5 follow-up: Changed 7 years ago by leif

"My Gentoo Linux system" isn't very precise.

Note that (also Sage's) readline uses some termcap library, i.e. some "arbitrary" equivalent installed / found on a user's system, which apparently leads to improper output of control sequences (intended to be handled by the terminal) in some (mis-)configurations; cf. also this Python bug report.

Unsetting TERM unfortunately doesn't "effectively disable readline", but may trigger other bugs, like the one reported here. Using TERM=unknown (or none) or something like that instead would perhaps avoid both.

comment:6 in reply to: ↑ 5 ; follow-up: Changed 7 years ago by jdemeyer

Replying to leif:

Unsetting TERM unfortunately doesn't "effectively disable readline", but may trigger other bugs, like the one reported here. Using TERM=unknown (or none) or something like that instead would perhaps avoid both.

I don't think that is a good solution, because we need Sage to work with TERM unset. Imagine for example somebody wants to run sage from a cron script, then TERM would not be set. Also, TERM is not set when you run something like

ssh mysagebox "sage script.sage"

comment:7 in reply to: ↑ 6 Changed 7 years ago by leif

Replying to jdemeyer:

I don't think that is a good solution, because we need Sage to work with TERM unset.

Well, then someoneTM has to track down the (rare?) segfault reported at #11970... ;P

comment:8 follow-up: Changed 7 years ago by wjp

Out of curiosity, do you really get an unset TERM in cron jobs and non-interactive ssh sessions? On all of the systems I've tried, it's always 'dumb'.

For context, this is readline outputting the "meta mode on"/"smm" sequence to enable 8 bit mode. This is signalled by the "km" termcap flag, viewable using 'infocmp', where you can also directly see the "smm" sequence.

comment:9 in reply to: ↑ 8 Changed 7 years ago by jdemeyer

Replying to wjp:

Out of curiosity, do you really get an unset TERM in cron jobs and non-interactive ssh sessions? On all of the systems I've tried, it's always 'dumb'.

Are you sure there is an environment variable "TERM" in the cases you mention? It seems to me that bash sets a non-exported variable TERM=dumb if there is no environment variable TERM. You can see this with "declare -p TERM". In a normal shell, I get for example

$ declare -p TERM
declare -x TERM="xterm"

(the -x means exported)

With a non-interactive ssh session:

$ ssh sage.math.washington.edu "declare -p TERM"
declare -- TERM="dumb"

(no -x, so not exported, i.e. not an environment variable)

Note: See TracTickets for help on using tickets.