468,161 Members | 1,918 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,161 developers. It's quick & easy.

wxpython thread exception crash

What am I doing wrong?
I'm trying to capture stdErr in a multi-threaded program.

This code crashes wxPython with
/Py Assertion Error: C++ assertion "m_count=-1 || m_count=-2" failed/

What I'm trying to do is redirect stderr and stdout to a wxPython text
control.
In an ideal world, when the worker thread crashes, I should get a stderr
message, with no effect on the main thread.

In an alternate world, I should get an asynchronous exception in the
main thread when there is an unhandled exception in the worker thread.

In the sample below, the program crashes on the following print statement.

Oddly enough, I do catch the unhandled worker exception in the main
thread IF THE WORKER THREAD HAS NO INIT PARAMETER. Note: the init
parameter is the only subtle thing in the code.

Since this is a crash, the exact behaviour will depend on your
environment. You may have difficulty seeing stdErr in some environments.

Python 2.5, wxPython 2.7.2.0, Windows XP.
(david)

--------
import wx
import sys
import threading

class ExceptionThread(threading.Thread):
def __init__(self,initvar):
threading.Thread.__init__(self);

def run(self):
raise "ET run"
class RedirectText:
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl

def write(self,string):
self.out.WriteText(string)

def flush(self):
pass

class Frame(wx.Frame):
def __init__(self, image=None, parent=None):

wx.Frame.__init__(self, parent)
self.text = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_RICH2)

#---- redirection window ----
redir=RedirectText(self.text)
sys.stdout=redir
sys.stderr=redir
class App(wx.App):
def OnInit(self):
self.frame=Frame()
self.frame.Show()
self.Thread=ExceptionThread(1)
self.Thread.start();
return True
app = App()
print 'trigger print failure'
app.MainLoop()
Aug 21 '07 #1
1 2066
class RedirectText:
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl

def write(self,string):
wx.CallAfter(self.out.WriteText,string) #CallAfter

def flush(self):
pass

[david]

[david] wrote:
What am I doing wrong?
I'm trying to capture stdErr in a multi-threaded program.

This code crashes wxPython with
/Py Assertion Error: C++ assertion "m_count=-1 || m_count=-2" failed/

What I'm trying to do is redirect stderr and stdout to a wxPython text
control.
In an ideal world, when the worker thread crashes, I should get a stderr
message, with no effect on the main thread.

In an alternate world, I should get an asynchronous exception in the
main thread when there is an unhandled exception in the worker thread.

In the sample below, the program crashes on the following print statement.

Oddly enough, I do catch the unhandled worker exception in the main
thread IF THE WORKER THREAD HAS NO INIT PARAMETER. Note: the init
parameter is the only subtle thing in the code.

Since this is a crash, the exact behaviour will depend on your
environment. You may have difficulty seeing stdErr in some environments.

Python 2.5, wxPython 2.7.2.0, Windows XP.
(david)

--------
import wx
import sys
import threading

class ExceptionThread(threading.Thread):
def __init__(self,initvar):
threading.Thread.__init__(self);

def run(self):
raise "ET run"
class RedirectText:
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl

def write(self,string):
self.out.WriteText(string)

def flush(self):
pass

class Frame(wx.Frame):
def __init__(self, image=None, parent=None):

wx.Frame.__init__(self, parent)
self.text = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_RICH2)

#---- redirection window ----
redir=RedirectText(self.text)
sys.stdout=redir
sys.stderr=redir
class App(wx.App):
def OnInit(self):
self.frame=Frame()
self.frame.Show()
self.Thread=ExceptionThread(1)
self.Thread.start();
return True
app = App()
print 'trigger print failure'
app.MainLoop()

Aug 27 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by BJörn Lindqvist | last post: by
16 posts views Thread by droopytoon | last post: by
9 posts views Thread by Lonnie Princehouse | last post: by
2 posts views Thread by =?Utf-8?B?Wmhlbnlh?= | last post: by
16 posts views Thread by Andrea Gavana | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.