473,698 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Thre ad):
def __init__(self,i nitvar):
threading.Threa d.__init__(self );

def run(self):
raise "ET run"
class RedirectText:
def __init__(self,a WxTextCtrl):
self.out=aWxTex tCtrl

def write(self,stri ng):
self.out.WriteT ext(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(sel f, style=wx.TE_MUL TILINE|wx.TE_RI CH2)

#---- redirection window ----
redir=RedirectT ext(self.text)
sys.stdout=redi r
sys.stderr=redi r
class App(wx.App):
def OnInit(self):
self.frame=Fram e()
self.frame.Show ()
self.Thread=Exc eptionThread(1)
self.Thread.sta rt();
return True
app = App()
print 'trigger print failure'
app.MainLoop()
Aug 21 '07 #1
1 2291
class RedirectText:
def __init__(self,a WxTextCtrl):
self.out=aWxTex tCtrl

def write(self,stri ng):
wx.CallAfter(se lf.out.WriteTex t,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.Thre ad):
def __init__(self,i nitvar):
threading.Threa d.__init__(self );

def run(self):
raise "ET run"
class RedirectText:
def __init__(self,a WxTextCtrl):
self.out=aWxTex tCtrl

def write(self,stri ng):
self.out.WriteT ext(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(sel f, style=wx.TE_MUL TILINE|wx.TE_RI CH2)

#---- redirection window ----
redir=RedirectT ext(self.text)
sys.stdout=redi r
sys.stderr=redi r
class App(wx.App):
def OnInit(self):
self.frame=Fram e()
self.frame.Show ()
self.Thread=Exc eptionThread(1)
self.Thread.sta rt();
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
2413
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
3348
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 Python GUI toolkit is that Tkinter was there first." - Guido van Rossum Guess, that answers my question, but isn't "Tkinter was there first" a very bad answer? :) It is kinda ugly too, so I wonder why it can't be replaced? Or maybe another GUI...
5
10667
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 thread is spawned (threading module) and this thread starts listening for data on a socket. When someone connects, a new thread is spawned, It needs to do I/O on that socket and open a GUI window so the user can communicate with the client...
16
3298
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 have a thread "_itTaskThread" running. The application is listening on a TCP port. It accepts 2 connection from a client. I simulate a crash on the client side (using "Debug->StopDebugging").
9
1610
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 crash horribly, post which versions of (Python, wxPython) they are using? I can't find other messages related to this, so I suspect it is something broken with my installation. I'm using Python 2.4.2 and wx 2.6.1.0.
9
5548
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. But the "app.MainLoop()" in wxpython looks like conflicting with the "while 1:" in socket server. After I commented the "app.MainLoop()", everything is working except two things: 1. if I click anywhere on the screen with the mouse, the image is...
3
1608
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 thread, that does nothing but increment a counter and print its value to the screen, then afterwards, I start the wxPython application. I get nothing but weird behavior: sometimes the gui just crashes, sometimes I get an exception, sometimes it runs for...
2
1301
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 exception on the main thread. Is there any way to throw an exception on one thread and catch it on another thread? If #1 is not possible, is there a catch-all exception handler at the process
16
2401
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 in particular, but I am curious to know why some people find it "ugly" or "bad" or whatever. It has its own bugs and missing features, of course, but it is one of the major GUI player in the arena, together with PyQt and PyGTK.
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7732
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.