This is my first foray into threading, so apologies for any obvious mistakes.
I have a PyQt widget, from which a new process, prog, is run in a different thread.  In my main thread, I'm also redirecting stdout to a read-only QTextEdit. However, I get errors referring to recursion, and I'm worried that my threads are interfering in each other in a way which causes a print statement to go into an infinite loop. I only get these errors if I run prog from the GUI, and not from the command line.  My stdout redirect is using the code in this SO answer
In pseudo-code, this is basically what I've got:
gui.py
class widget(QWidget):
  def __init__(self):
    self.button = QPushButton("GO!", self)
    self.button.clicked.connect(self.start)
  def start(self):
    self.thread = TaskThread()
    sys.stdout = EmittingStream(textWritten = self.outputText)
    self.thread.start()
  def outputText(self):
    #as in answer provided in link (EmittingStream in separate module)
prog.py
class TaskThread(QThread):
  def run(self):
    '''
      Long complicated program; putting in simpler code here (e.g. loop printing to 10000) doesn't reproduce errors 
    '''
- Is there any way of finding out if my recursion is caused by an infinite loop, or by anything else?
- Is my code obviously thread-unsafe?
- How do you make functions guaranteed to be threadsafe? (Links to tutorials / books will be good!)
 
     
     
     
    