472,359 Members | 1,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,359 software developers and data experts.

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 2202
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: mike420 | last post by:
Tayss wrote: > > app = wxPySimpleApp() > frame = MainWindow(None, -1, "A window") > frame.Show(True) > app.MainLoop() > Why do you need a macro for that? Why don't you just write
25
by: BJörn Lindqvist | last post by:
See: http://www.wxpython.org/quotes.php. especially: "wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard...
5
by: fooooo | last post by:
This is a network app, written in wxPython and the socket module. This is what I want to happen: GUI app starts. User clicks a button to 'start' the work of the app. When start is pressed, a new...
16
by: droopytoon | last post by:
Hi, I start a new thread (previous one was "thread timing") because I have isolated my problem. It has nothing to do with calling unmanaged C++ code (I removed it in a test application). I...
9
by: Lonnie Princehouse | last post by:
Hi all, I'm getting a seg fault when I try to use minidom to parse some XML inside a wxPython app. I was wondering if someone else could run the simple code below on Linux and, if it doesn't...
9
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame....
3
by: Shafik | last post by:
Hello folks, I'm having an issue with mixing wxPython and threading ... I realize multi-threading always introduces subtle bugs, but the following scenario is just odd: I start a dummy...
2
by: =?Utf-8?B?Wmhlbnlh?= | last post by:
Hello, I am a C++ newbie. I developed a Win32 DLL that creates a number of threads, which can throw exceptions. When an exception is thrown on a thread in Win32 DLL, I want to catch that...
16
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.