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 2264
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |