Repository: psychopy/psychopy

Issue:
No error or logging messages in Runner Stdout when preferences `errorDialog = True` 
No error or logging messages are written to the Runner Stdout in v2020.2.3 on Win10.


Discussion:
Does this issue resolve itself after restarting?

Devs: I think we need to update the error callback after the pref changes. 
That setting is just for showing an error dlg when the PsychoPy app itself encounters an error I believe - errors should always write to the Runner Stdout. What error were you getting which wasn't writing to the Stdout? I'll try to replicate this and see what's going wrong
Sometimes, restarting Psychopy helps. I'm unsure under what conditions I don't get output. Could you point me in the direction what I could do to narrow down possible causes?

Could the problem be that I close the Runner window? If I then send an experiment to the Runner, I still see the old runner window greyed out under the Window tab and a second Runner window.

@TEParsons: It is not connected to a specific error type. The script I use for troubleshooting is: 
```
from psychopy import logging

# print
print('This is a string passed to a print statement')

# logging
logFile = logging.LogFile('test.log', level=logging.DEBUG)
logging.console.setLevel(logging.DEBUG)  # this outputs to the screen, not a file
logging.error('This is a string passed to logging.error')
logging.debug('This is a string passed to logging.debug')
logging.flush()

# this will throw an error
aNonExistingVariable
```
I get output, when I do the following:
1. Open the Runner with CMD: `"C:\Program Files\PsychoPy3\pythonw.exe" "C:\Program Files\PsychoPy3\Lib\site-packages\psychopy\app\psychopyApp.py" --runner`
2. Add the script test_stdout.py (see post above).
3. Run the script

I don't get output, when I do these steps:
1. Open the Coder with CMD: `"C:\Program Files\PsychoPy3\pythonw.exe" "C:\Program Files\PsychoPy3\Lib\site-packages\psychopy\app\psychopyApp.py" --coder`
2. Open a Runner window from the `window` tab
3. Close the Runner window
4. Open a Runner window from the `window` tab
5. Add the script test_stdout.py (see post above)
6. Run the script

**BUT for the Builder interface and .psyexp files**, I couldn't find the same pattern yet. I'm still trying different start-up options there.
The greyed out buttons themselves probably aren't the cause - originally we had it set to delete buttons when the corresponding window was closed, but the delete command caused a seg fault on Mac so now it just disables the button. However, closing and opening the Runner a few times might be what does it - it could be that output is being sent to one of the closed Runner windows.  When I try running a file with print/logging statements in as you suggested after closing and reopening Runner a few times it does mute the output.
For .psyexp files, I found, that when I start Psychopy with the `-c` flag, then open a builder window from the window tab, open a .psyexp file and run it, I get output. However, when I open the builder directly with the `-b` flag, open a .psyexp file and run it, I get no output.

Resolving patch:
diff --git a/psychopy/app/_psychopyApp.py b/psychopy/app/_psychopyApp.py
--- a/psychopy/app/_psychopyApp.py
+++ b/psychopy/app/_psychopyApp.py
@@ -424,10 +424,6 @@ def onInit(self, showSplash=True, testMode=False):
         # we wanted debug mode while loading but safe to go back to info mode
         if not self.prefs.app['debugMode']:
             logging.console.setLevel(logging.INFO)
-        # Runner captures standard streams until program closed
-        if self.runner and not self.testMode:
-            sys.stdout = self.runner.stdOut
-            sys.stderr = self.runner.stdOut
 
         return True
 
@@ -590,6 +586,10 @@ def showRunner(self, event=None, fileList=[]):
             self.runner.Show()
             self.runner.Raise()
             self.SetTopWindow(self.runner)
+        # Runner captures standard streams until program closed
+        if self.runner and not self.testMode:
+            sys.stdout = self.runner.stdOut
+            sys.stderr = self.runner.stdOut
 
     def newRunnerFrame(self, event=None):
         # have to reimport because it is only local to __init__ so far


Test patch: