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() 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()
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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++...
|
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...
|
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...
| |