Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Threadsafe capturing stdout to a TextCtrl
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chris Weisiger  
View profile  
 More options Nov 15 2012, 4:12 pm
From: Chris Weisiger <cweisi...@msg.ucsf.edu>
Date: Thu, 15 Nov 2012 13:11:59 -0800
Local: Thurs, Nov 15 2012 4:11 pm
Subject: Threadsafe capturing stdout to a TextCtrl
I have a program where I want to be able to have print statements get
written to a TextCtrl, and errors show up in another. So I made my two
TextCtrls and assigned them to sys.stdout and sys.stderr. So far so
good. However, sometimes when I print to them, I get this error:

Traceback (most recent call last):
  File "C:\Python27x64\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py",
line 14660, in <lambda>
    lambda event: event.callable(*event.args, **event.kw) )
  File "C:\mui\gui\loggingWindow.py", line 48, in stdOut
    window.stdOut.write(' '.join([str(s) for s in args]))
  File "C:\Python27x64\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py",
line 1990, in write
    return _controls_.TextCtrl_write(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "m_count == -1 || m_count ==
-2" failed at ..\..\src\msw\textctrl.cpp(140) in
UpdatesCountFilter::UpdatesCountFilter(): wrong initial m_updatesCount
value

I'm guessing the problem is that print statements made outside of the
main thread are causing UI updates when those should only happen in
the main thread. I tried working around it by overriding the
TextCtrl.write method:

        self.stdOut.__labWrite = self.stdOut.write
        self.stdOut.write = lambda *args:
wx.CallAfter(self.stdOut.__labWrite(*args))

but this results in massive error spew about NoneType not being
callable. Oddly this shows up in my stderr window just fine, but the
spew locks up the program and I can't copy&paste it.

So what's the proper way to capture stdout and stderr to a text control?

-Chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.