so I've learned that emacs cannot handle multi-line strings very well, for example printing big data structures in inferior python shell (invoked with run-python) is dangerous and usually ends with massive slowdown of whole emacs or crash. To bypass this, I print datastructures by elements and I ran into this odd behaviour:

for i in [('a', 'b') for j in range(150000)]:

No lines involved here, still emacs behaves like they were: massive slowdown, usually crash.

This code is ok (why??):

for i in [(1, 2) for j in range(150000):

BTW: I run emacs with -q, I've tried using alternative python shells (ipython) and I tried buffer-disable-undo.

Thanks for help, I really love the idea of having python shell in emacs and I've invested many hours into research about this, but without any results.

  • I'm unsure what you're asking. I ran the first code block (in ipython within emacs) without any problems. Could you clarify what you're looking for?
    – GJStein
    Jul 14, 2015 at 23:52
  • On my machine the output starts to slow down very fast and then emacs freeze. I tried using ipython, same result.
    – user8918
    Jul 15, 2015 at 12:09
  • The first uses quotes, the second doesn't. So, font-locking needs to be applied in the first case and not in the second one. I'd expect font-locking of strings to be fairly fast, but Python can't reuse syntax tables because of their triple quotes, so IIRC their reimplementation of string fontlocking is always used and relatively slow in this situation (a single, long line).
    – wasamasa
    Sep 14, 2015 at 18:52

1 Answer 1


A little bit of guesswork here, but I've found that turning off font-locking makes printing large output much faster. On my system printing speed is tolerable with

(setq python-shell-enable-font-lock nil)

and intolerably slow otherwise. Note that the python process needs to be restarted for this to take effect.

  • In 24.5 font-lock is only enabled for the input line here and that fixes this issue for me.
    – wasamasa
    Sep 14, 2015 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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