Background :I have a wxpython based gui. My python version is 2.5 and my wxpython version is 2.8 . Unfortunately I can’t migrate to newer versions because other internal tools might break.
In my gui, I have a list of test files got by walking through my test directory and these displayed using a wxPython ListCtrl. The user selects one or more test files. and then presses my defined Execute Button. In function binded to this Execute button I run the test python file by using the import functionality present in python
These test files are executed one by one.The output of each of these test files is redirected to a logger and displayed in wxpython txtctrl in my gui and as well to text file. Each test may take several minutes and runs on my attached hardware.After all the tests return as I can see in messages in the txtctrl log window… When I make new selections in my ListCtrl, and then when I press any of defined buttons on my GUI like the “Execute” button or any other button ,My GUI closes unexpectedly after that and I am unable to debug the reason . How do I debug this and where do I start.?
I tried using
app = wx.PySimpleApp(redirect=True)
app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt") but I am unable to catch errors.
Background :I have a wxpython based gui. My python version is 2.5 and my
wxpython version is 2.8 . Unfortunately I can't migrate to newer
versions because other internal tools might break.
In my gui, I have a list of test files got by
walking through my test directory and these displayed using a wxPython
ListCtrl. The user selects one or more test files. and then presses my
defined Execute Button. In function binded to this Execute button I run
the test python file by using the import functionality present in python
These test files are executed one by one.The output of each of these
test files is redirected to a logger and displayed in wxpython txtctrl
in my gui and as well to text file. Each test may take several minutes
and runs on my attached hardware.After all the tests return as I can
see in messages in the txtctrl log window.. When I make new
selections in my ListCtrl, and then when I press any of defined buttons
on my GUI like the "Execute" button or any other button ,My GUI closes
unexpectedly after that and I am unable to debug the reason . How do I
debug this and where do I start.?
Try running from a console or terminal window and turn off the redirection of stdout and stderr. Then if there is a python exception at the time of the exit you should be able to see it in the terminal
I tried using
app = wx.PySimpleApp(redirect=True)
app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt") but I
am unable to catch errors.
I also tried using a try except block like this :
app = wx.PySimpleApp(redirect=True)
app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt")
try:
wx.InitAllImageHandlers()
frame_1 = MainGUI(None, -1, "Tester")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()
except:
show_error()
My python version is 2.5.4 and wxpython version is 2.8.7.1 and my OS
is Windows XPSP2.
I am not using any threads.Just using __import__ for this. I will try
to build a sample app. I tried running through a console also but
application closes and I don't get any exception.
···
On Nov 3, 9:52 pm, Robin Dunn <ro...@alldunn.com> wrote:
On 11/2/11 11:38 PM, michelle yaobao wrote:
> Background :I have a wxpython based gui. My python version is 2.5 and my
> wxpython version is 2.8 . Unfortunately I can't migrate to newer
> versions because other internal tools might break.
> In my gui, I have a list of test files got by
> walking through my test directory and these displayed using a wxPython
> ListCtrl. The user selects one or more test files. and then presses my
> defined Execute Button. In function binded to this Execute button I run
> the test python file by using the import functionality present in python
> These test files are executed one by one.The output of each of these
> test files is redirected to a logger and displayed in wxpython txtctrl
> in my gui and as well to text file. Each test may take several minutes
> and runs on my attached hardware.After all the tests return as I can
> see in messages in the txtctrl log window.. When I make new
> selections in my ListCtrl, and then when I press any of defined buttons
> on my GUI like the "Execute" button or any other button ,My GUI closes
> unexpectedly after that and I am unable to debug the reason . How do I
> debug this and where do I start.?
Try running from a console or terminal window and turn off the
redirection of stdout and stderr. Then if there is a python exception
at the time of the exit you should be able to see it in the terminal
> I tried using
> app = wx.PySimpleApp(redirect=True)
> app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt") but I
> am unable to catch errors.
> I also tried using a try except block like this :
> app = wx.PySimpleApp(redirect=True)
> app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt")
> try:
> wx.InitAllImageHandlers()
> frame_1 = MainGUI(None, -1, "Tester")
> app.SetTopWindow(frame_1)
> frame_1.Show()
> app.MainLoop()
> except:
> show_error()
To add to my previous message.
I am just importing the test and using this type of python code to run:
t = mytest.myTestClass()
testResult = t.myTestFunction()
In this test function we use our internal python modules to program the hardware.
While trying to build the sample app, I have noticed that we do not use our internal python library to program the hardware, my program does not crash. Before jumping to the conclusion that the internal library is the problem, that library has been in use for quite sometime and has been pretty well tested. So I want to make sure that the the problem is not in my code.
I am not using any threads.Just using __import__ for this.
I, of course, don't know that details of your use-case, but it sure seems to me that you'd be a lot better off running your tests in another process, rather than the same instance of Python that your GUI is running in.
If nothing else, then a hard crash of a test wouldn't bring down you GUI -- which may or may not be what happening here, but you can see how it would be an advantage!
-Chris
···
On 11/3/11 9:43 PM, michelle wrote:
On Nov 3, 9:52 pm, Robin Dunn<ro...@alldunn.com> wrote:
On 11/2/11 11:38 PM, michelle yaobao wrote:
Background :I have a wxpython based gui. My python version is 2.5 and my
wxpython version is 2.8 . Unfortunately I can't migrate to newer
versions because other internal tools might break.
In my gui, I have a list of test files got by
walking through my test directory and these displayed using a wxPython
ListCtrl. The user selects one or more test files. and then presses my
defined Execute Button. In function binded to this Execute button I run
the test python file by using the import functionality present in python
These test files are executed one by one.The output of each of these
test files is redirected to a logger and displayed in wxpython txtctrl
in my gui and as well to text file. Each test may take several minutes
and runs on my attached hardware.After all the tests return as I can
see in messages in the txtctrl log window.. When I make new
selections in my ListCtrl, and then when I press any of defined buttons
on my GUI like the "Execute" button or any other button ,My GUI closes
unexpectedly after that and I am unable to debug the reason . How do I
debug this and where do I start.?
Try running from a console or terminal window and turn off the
redirection of stdout and stderr. Then if there is a python exception
at the time of the exit you should be able to see it in the terminal
I tried using
app = wx.PySimpleApp(redirect=True)
app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt") but I
am unable to catch errors.
I also tried using a try except block like this :
app = wx.PySimpleApp(redirect=True)
app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt")
try:
wx.InitAllImageHandlers()
frame_1 = MainGUI(None, -1, "Tester")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()
except:
show_error()
--
Robin Dunn
Software Craftsmanhttp://wxPython.org- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris
Are you suggesting I use Python multiprocessing module ? My
interaction with the tests is limited to run the test, display test
logging messages on my GUI txt ctrl window and build a table based on
the value returned by test (like PASS or FAIL) etc.
···
On Nov 4, 11:37 am, "Chris.Barker" <Chris.Bar...@noaa.gov> wrote:
On 11/3/11 9:43 PM, michelle wrote:
> I am not using any threads.Just using __import__ for this.
I, of course, don't know that details of your use-case, but it sure
seems to me that you'd be a lot better off running your tests in another
process, rather than the same instance of Python that your GUI is
running in.
If nothing else, then a hard crash of a test wouldn't bring down you GUI
-- which may or may not be what happening here, but you can see how it
would be an advantage!
-Chris
> On Nov 3, 9:52 pm, Robin Dunn<ro...@alldunn.com> wrote:
>> On 11/2/11 11:38 PM, michelle yaobao wrote:
>>> Background :I have a wxpython based gui. My python version is 2.5 and my
>>> wxpython version is 2.8 . Unfortunately I can't migrate to newer
>>> versions because other internal tools might break.
>>> In my gui, I have a list of test files got by
>>> walking through my test directory and these displayed using a wxPython
>>> ListCtrl. The user selects one or more test files. and then presses my
>>> defined Execute Button. In function binded to this Execute button I run
>>> the test python file by using the import functionality present in python
>>> These test files are executed one by one.The output of each of these
>>> test files is redirected to a logger and displayed in wxpython txtctrl
>>> in my gui and as well to text file. Each test may take several minutes
>>> and runs on my attached hardware.After all the tests return as I can
>>> see in messages in the txtctrl log window.. When I make new
>>> selections in my ListCtrl, and then when I press any of defined buttons
>>> on my GUI like the "Execute" button or any other button ,My GUI closes
>>> unexpectedly after that and I am unable to debug the reason . How do I
>>> debug this and where do I start.?
>> Try running from a console or terminal window and turn off the
>> redirection of stdout and stderr. Then if there is a python exception
>> at the time of the exit you should be able to see it in the terminal
>>> I tried using
>>> app = wx.PySimpleApp(redirect=True)
>>> app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt") but I
>>> am unable to catch errors.
>>> I also tried using a try except block like this :
>>> app = wx.PySimpleApp(redirect=True)
>>> app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt")
>>> try:
>>> wx.InitAllImageHandlers()
>>> frame_1 = MainGUI(None, -1, "Tester")
>>> app.SetTopWindow(frame_1)
>>> frame_1.Show()
>>> app.MainLoop()
>>> except:
>>> show_error()
>> --
>> Robin Dunn
>> Software Craftsmanhttp://wxPython.org-Hide quoted text -
>> - Show quoted text -- Hide quoted text -
>> - Show quoted text -
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
I am attaching a sample which works (as it does not program the hardware as I said in my earlier message) . Should I incorporate threading or multiprocessing into it ?
On Thu, Nov 3, 2011 at 10:22 PM, Robin Dunn robin@alldunn.com wrote:
On 11/2/11 11:38 PM, michelle yaobao wrote:
Background :I have a wxpython based gui. My python version is 2.5 and my
wxpython version is 2.8 . Unfortunately I can’t migrate to newer
versions because other internal tools might break.
In my gui, I have a list of test files got by
walking through my test directory and these displayed using a wxPython
ListCtrl. The user selects one or more test files. and then presses my
defined Execute Button. In function binded to this Execute button I run
the test python file by using the import functionality present in python
These test files are executed one by one.The output of each of these
test files is redirected to a logger and displayed in wxpython txtctrl
in my gui and as well to text file. Each test may take several minutes
and runs on my attached hardware.After all the tests return as I can
see in messages in the txtctrl log window… When I make new
selections in my ListCtrl, and then when I press any of defined buttons
on my GUI like the “Execute” button or any other button ,My GUI closes
unexpectedly after that and I am unable to debug the reason . How do I
debug this and where do I start.?
Try running from a console or terminal window and turn off the redirection of stdout and stderr. Then if there is a python exception at the time of the exit you should be able to see it in the terminal
I tried using
app = wx.PySimpleApp(redirect=True)
app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt") but I
am unable to catch errors.
I also tried using a try except block like this :
app = wx.PySimpleApp(redirect=True)
app = wx.PySimpleApp(redirect=True,filename=“mylogfile.txt”)
try:
Unhandled exception in thread started by <bound method MainGUI.longRunning of <_ main_.MainGUI; proxy of <Swig Object of type ‘wxFrame *’ at 0xa44210> >>
Traceback (most recent call last):
File “mysampleapp_withthreads.py”, line 248, in longRunning
wx.CallAfter(self.onLongRunDone)
File “C:\Python25\lib\site-packages\wx_core.py”, line 14363, in CallAfter
assert app is not None, 'No wx.App created yet'
AssertionError: No wx.App created yet
See attached files with this message. I really don’t know if it is related to my previous problem or not
I am attaching a sample which works (as it does not program the hardware as I said in my earlier message) . Should I incorporate threading or multiprocessing into it ?
Regards
michelle
On Thu, Nov 3, 2011 at 10:22 PM, Robin Dunn robin@alldunn.com wrote:
On 11/2/11 11:38 PM, michelle yaobao wrote:
Background :I have a wxpython based gui. My python version is 2.5 and my
wxpython version is 2.8 . Unfortunately I can’t migrate to newer
versions because other internal tools might break.
In my gui, I have a list of test files got by
walking through my test directory and these displayed using a wxPython
ListCtrl. The user selects one or more test files. and then presses my
defined Execute Button. In function binded to this Execute button I run
the test python file by using the import functionality present in python
These test files are executed one by one.The output of each of these
test files is redirected to a logger and displayed in wxpython txtctrl
in my gui and as well to text file. Each test may take several minutes
and runs on my attached hardware.After all the tests return as I can
see in messages in the txtctrl log window… When I make new
selections in my ListCtrl, and then when I press any of defined buttons
on my GUI like the “Execute” button or any other button ,My GUI closes
unexpectedly after that and I am unable to debug the reason . How do I
debug this and where do I start.?
Try running from a console or terminal window and turn off the redirection of stdout and stderr. Then if there is a python exception at the time of the exit you should be able to see it in the terminal
I tried using
app = wx.PySimpleApp(redirect=True)
app = wx.PySimpleApp(redirect=True,filename="mylogfile.txt") but I
am unable to catch errors.
I also tried using a try except block like this :
app = wx.PySimpleApp(redirect=True)
app = wx.PySimpleApp(redirect=True,filename=“mylogfile.txt”)
try:
This error normally means that you are trying to finish your thread
either before the wx.App is created or after it is deleted - if you
have not exited without letting the thread finish then something in
your thread may be deleting the app.
exception in thread started by <bound method
MainGUI.longRunning of <_
_main__.MainGUI; proxy of <Swig Object of type 'wxFrame *'
at 0xa44210> >>
Traceback (most recent call last):
File "mysampleapp_withthreads.py", line 248, in longRunning
wx.CallAfter(self.onLongRunDone)
File "C:\Python25\lib\site-packages\wx\_core.py", line
14363, in CallAfter
assert app is not None, 'No wx.App created yet'
AssertionError: No wx.App created yet
See attached files with this message. I really don't know if
Chris
Are you suggesting I use Python multiprocessing module ?
yes, or even a simple os.system() call or popen.
My
interaction with the tests is limited to run the test, display test
logging messages on my GUI txt ctrl window and build a table based on
the value returned by test (like PASS or FAIL) etc.
This sounds very well suited to running in another process.
As suggested,I modified it to use simple threading logic from here LongRunningTasks - wxPyWiki and got this exception:
That's an improvement, but I think you'd be better off with a separate process. If what you are testing is going to be run with a GUI and all that, then you should test it that way.
Threading introduces other issues that you may as well not deal with.
-Chris
···
On 11/4/11 12:21 AM, michelle wrote:
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
I don't get that error here, but it appears to be getting stuck and not completing the task, which may be related to the following.
I notice that you are doing a lot of interaction with the GUI from the worker thread in longRunning(). That is almost always a problem, so it is best that you do not directly execute any code that creates or manipulates UI elements from anywhere but the main thread. You can use things like sending custom events or using wx.CallAfter to communicate from the worker thread to the main thread where you can interact with the UI.
Although, like others have suggested, I think that it probably makes more sense in your case to run your test files in a separate process. That way there is zero impact on the process that is running your GUI, and the test files will have a clean environment to run within. You may still want to have a worker thread in your GUI application to monitor the status of the child processes, load their log text and send it to the GUI thread for display, etc.
···
On 11/4/11 6:05 AM, michelle yaobao wrote:
Hello All
As suggested,I modified it to use simple threading logic from here LongRunningTasks - wxPyWiki and got this exception:
Python version 2.5.4
WxPython ver: 2.8.7.1
OS : Windows XPSP2
Unhandled exception in thread started by <bound method
MainGUI.longRunning of <_
_main__.MainGUI; proxy of <Swig Object of type 'wxFrame *' at 0xa44210> >>
Traceback (most recent call last):
File "mysampleapp_withthreads.py", line 248, in longRunning
wx.CallAfter(self.onLongRunDone)
File "C:\Python25\lib\site-packages\wx\_core.py", line 14363, in
CallAfter
assert app is not None, 'No wx.App created yet'
AssertionError: No wx.App created yet
See attached files with this message. I really don't know if it is
related to my previous problem or not
Based on the advice I got from this forum, I have tried to solve my problem using subprocess but I am unable to catch logging o/p in my txt ctrl. I would like to capture log o/p in my txt ctrl from both main file and the test file and clear text in the txt ctrl.
See attached sample for details. I am sure I am doing something silly but unable to put a finger on it.
Python version 2.5.4
WxPython ver: 2.8.7.1
OS : Windows XPSP2
Unhandled exception in thread started by <bound method
MainGUI.longRunning of <_ main_.MainGUI; proxy of <Swig Object of type ‘wxFrame *’ at 0xa44210> >>
Traceback (most recent call last):
File “mysampleapp_withthreads.py”, line 248, in longRunning
wx.CallAfter(self.onLongRunDone)
File “C:\Python25\lib\site-packages\wx_core.py”, line 14363, in
CallAfter
assert app is not None, ‘No wx.App created yet’
AssertionError: No wx.App created yet
See attached files with this message. I really don’t know if it is
related to my previous problem or not
I don’t get that error here, but it appears to be getting stuck and not completing the task, which may be related to the following.
I notice that you are doing a lot of interaction with the GUI from the worker thread in longRunning(). That is almost always a problem, so it is best that you do not directly execute any code that creates or manipulates UI elements from anywhere but the main thread. You can use things like sending custom events or using wx.CallAfter to communicate from the worker thread to the main thread where you can interact with the UI.
Although, like others have suggested, I think that it probably makes more sense in your case to run your test files in a separate process. That way there is zero impact on the process that is running your GUI, and the test files will have a clean environment to run within. You may still want to have a worker thread in your GUI application to monitor the status of the child processes, load their log text and send it to the GUI thread for display, etc.
In order for the log messages to be received from the child process they need to be written to stdout, and if you run the sample_test.py module directly you'll see that there is no output at all. You need to either configure a handler and a log level for your logger, or do something like call logging.basicConfig(level=logging.INFO) and use logger.info instead of mylog.info.
···
On 11/10/11 2:41 AM, michelle yaobao wrote:
Based on the advice I got from this forum, I have tried to solve my
problem using subprocess but I am unable to catch logging o/p in my txt
ctrl. I would like to capture log o/p in my txt ctrl from both main file
and the test file and clear text in the txt ctrl.
See attached sample for details. I am sure I am doing something silly
but unable to put a finger on it.
Thanks for the help.
But that is what I want, only to redirect a few things to stdout and most of the stuff to logger.
···
On Thu, Nov 10, 2011 at 11:58 PM, Robin Dunn robin@alldunn.com wrote:
On 11/10/11 2:41 AM, michelle yaobao wrote:
Based on the advice I got from this forum, I have tried to solve my
problem using subprocess but I am unable to catch logging o/p in my txt
ctrl. I would like to capture log o/p in my txt ctrl from both main file
and the test file and clear text in the txt ctrl.
See attached sample for details. I am sure I am doing something silly
but unable to put a finger on it.
Thanks for the help.
In order for the log messages to be received from the child process they need to be written to stdout, and if you run the sample_test.py module directly you’ll see that there is no output at all. You need to either configure a handler and a log level for your logger, or do something like call logging.basicConfig(level=logging.INFO) and use logger.info instead of mylog.info.