import Queue
import wx, wx.stc
from editor_fonts import init_stc_style

class ThreadOutputCtrl(wx.stc.StyledTextCtrl):
    def __init__(self, parent, style=wx.TE_READONLY):
        wx.stc.StyledTextCtrl.__init__(self, parent)
        init_stc_style(self)
        self.SetIndent(4)
        self.SetTabWidth(8)
        self.SetUseTabs(False)

        self.queue = Queue.Queue(1024)
        self.timer = wx.Timer(self)

        self.Bind(wx.EVT_TIMER, self.__OnTimer, self.timer)

    def __OnTimer(self, evt):
        self.flush()

    def flush(self):
        lines = "".join(self.queue.get_nowait() for _ in xrange(self.queue.qsize()))
        if lines:
            self.AppendText(lines)

    def start(self, interval=100):
        self.timer.Start(interval)

    def stop(self):
        self.timer.Stop()
        wx.CallAfter(self.flush)

    def write(self, s):
        self.queue.put(s)

    def IsEmpty(self):
        return self.GetTextLength() == 0

@@ -1,20 +1,24 @@
 import 
-Queue
+threading
 %0Aimport 
@@ -355,33 +355,59 @@
 elf.
-queue = Queue.Queue(1024)
+__lock = threading.Lock()%0A        self.__queue = %5B%5D
 %0A   
@@ -412,24 +412,26 @@
        self.
+__
 timer = wx.T
@@ -491,24 +491,26 @@
 Timer, self.
+__
 timer)%0A%0A    
@@ -590,83 +590,106 @@
     
-lines = %22%22.join(self.queue.get_nowait() for _ in xrange(
+with self.__lock:%0A            queue, self.__queue = 
 self.
+__
 queue
-.qsize())
+, %5B%5D%0A        lines = %22%22.join(queue
 )%0A  
@@ -780,32 +780,34 @@
 ):%0A        self.
+__
 timer.Start(inte
@@ -846,16 +846,18 @@
    self.
+__
 timer.St
@@ -931,22 +931,57 @@
     
-self.queue.put
+with self.__lock:%0A            self.__queue.append
 (s)%0A

Use a lock-protected list instead of a Queue.