Page 1 of 1

Unable to flush stderr

Posted: September 11th, 2016, 11:35 am
by Scorbie
I am using golly 2.8b1 and the following code results in an error.

Code: Select all

import sys
sys.stderr.flush()
I couldn't get the unittest module to work because of this, but I gave up to use it anyway, so not too important.
Edit: the error message:

Code: Select all

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/scorbie/.golly/golly_clip.py", line 2, in <module>
    sys.stderr.flush()
AttributeError: StderrCatcher instance has no attribute 'flush'

Re: Unable to flush stderr

Posted: September 13th, 2016, 11:15 pm
by Andrew
The error happens because Golly redefines sys.stderr to an internal class (StderrCatcher) that captures all error messages in a string that Golly can then display in a dialog box.

You could probably avoid the error by doing something like "sys.stderr.flush = pass" after importing sys.

Re: Unable to flush stderr

Posted: September 16th, 2016, 10:40 am
by Scorbie
Andrew wrote:You could probably avoid the error by doing something like "sys.stderr.flush = pass" after importing sys.
Ah! I'll try that next time. Thanks!