/
11.07.2016 at 12:00 am
Cuttings

SublimeREPL's Slow Printing/Freezing - A Solution

Applies when you're using the interpreter.

Sublime Text 3 may freeze if you use print long outputs via SublimeREPL. I'm not quite sure why.

I face this issue often, as I prefer to use the interpreter in Sublime Text (so as to avoid IDLE). Thankfully, someone on Github has deduced its potential cause and a solution:

"...It appears sublimeREPL buffers everything that it needs to print before updating the screen. This seems to be done one symbol at a time, and can cause performance issues with long strings. To change this functionality, go to the main plugin file (Packages\SublimeREPL\sublimerepl.py) and find the function handle_repl_output() in the ReplView class."

I don't understand Sublime Text's code base, but I tested his suggestions today, which works perfectly with Python 3 once you amend it to use range() instead of xrange() (as the latter has been deprecated).

Here's the modified code, to help anyone else out:

def handle_repl_output(self):
    """Returns new data from Repl and bool indicating if Repl is still working"""

    if self.repl.apiv2:
        try:
            while True:
                packet = self._repl_reader.queue.get_nowait()
                if packet is None:
                    return False

                self.handle_repl_packet(packet)

        except queue.Empty:
            return True

    else:
        try:
            packet = self._repl_reader.queue.get_nowait()
            if packet is None:
                return False
            for _ in range(1000):
                try:
                    packet += self._repl_reader.queue.get_nowait()
                except queue.Empty: break

            self.handle_repl_packet(packet)
            return True

        except queue.Empty:
            return True

The changes I see: A single if clause is added above try; an entire else clause is added after. Restoration requires only that you remove those, which is a fairly simple task.

As he further suggests, to improve the text speed, scroll down to def update_view_loop(self), then update as follows: sublime.set_timeout(self.update_view_loop, 1).


Filed under:
#
Words: 266 words approx.
Time to read: 1.06 mins (at 250 wpm)
Keywords:
, , , , , , , , ,

Other suggested posts

  1. 11.06.2022 at 09:09 pm / 大蛇に嫁いだ娘 - The Girl Married to the Giant Serpent
  2. 29.09.2020 at 12:24 pm / Rays of Circumstance
  3. 10.01.2020 at 10:40 am / Learned Lumber
  4. 16.12.2017 at 12:00 am / When Defying Simplicity
  5. 13.06.2015 at 12:00 am / Sexism Against Modern Men
  6. 12.06.2015 at 12:00 am / He Conquers Who Endures
  7. 05.07.2014 at 12:00 am / Jack Hamm on (Artistic) Practice
  8. 16.02.2014 at 12:00 am / Don't Care Too Much About Gear
  9. 28.11.2013 at 12:00 am / ケチ - Scroogean Niggardliness
  10. 25.09.2010 at 12:00 am / 汗牛充棟
© Wan Zafran. See disclaimer.