Hi,
I am using a wxPanel and wxGrid to input data then do calculations with it. I have a “run” menu button that goes to the calculations module.
The GUI looks fine until I start running the calculations, then some of the GUI goes blank.
If I click on another Window (in Windows 7), the python GUI will say ‘Not Responding’ at the top, even though the calculations are still running, and most of the GUI will be blank.
Once the calculations are done the wxpython GUI comes back to normal.
Has anyone else had this kind of issue?
Any suggestions on how to fix this?
I’d put up the code here but it is long, if needed I could reduce the code and put it up.
Thanks Roger
Hi Mike,
Thanks a million for the threading suggestion! Threading fixed the problem. Now my application runs smooth and doesn’t blank out or go ‘Not Responding’ even if I use other applications at the same time.
Thanks for your tutorial on thread safe wx. I will implement that later to be able to communicate back to main from the thread. So far I just changed the ‘Calculations’ module to a thread, that self runs when called from main. Here are all the changes I had to make to get it to work as a thread:
#add the import
from threading import Thread
#changed from:
class CalculatorClass:
#to:
class CalculatorClass(Thread):
#change from:
def init( self, SentInstance):
…
def CalculationClass(self):
… calculations here…
#to:
def init( self, SentInstance):
Thread.init(self)
#…
self.start()
def run(self):
… calculations here…
Thanks again
Roger
Hi Mike and All,
Well, I may have spoken a little to soon on this fix :\
The GUI lockup/blanking issues is cleared up fine. But a new problem surfaced.
From the GUI I run the thread that does the calculations. If I run the calculations twice, the GUI continues to work fine, but the thread freezes.
I am using matplotlib.pyplot to plot the data, and saving plots to files using savefig. So I never show() the plots.
The thread freezes on the second pass through as it is trying to create the figure on this line:
plt.figure(0,figsize = (5,5), dpi = 300))
I also have a line:
plt.close(‘all’)
which I believe should close out the plot after each pass.
Oddly, I close and create the figure a few times within the thread. And this works fine. But on the second pass to the Thread it locks up the first time I try to create a figure.
I also tried the code using multiprocessing, that caused the GUI lockup/blanking issue, but fixed the freeze on second pass issue :[
Any suggestions are appreciated.
Thanks
Roger
···
On Wednesday, April 3, 2013 4:29:05 PM UTC-6, Roger Zimmerman wrote:
Hi Mike,
Thanks a million for the threading suggestion! Threading fixed the problem. Now my application runs smooth and doesn’t blank out or go ‘Not Responding’ even if I use other applications at the same time.
Thanks for your tutorial on thread safe wx. I will implement that later to be able to communicate back to main from the thread. So far I just changed the ‘Calculations’ module to a thread, that self runs when called from main. Here are all the changes I had to make to get it to work as a thread:
#add the import
from threading import Thread
#changed from:
class CalculatorClass:
#to:
class CalculatorClass(Thread):
#change from:
def init( self, SentInstance):
…
def CalculationClass(self):
… calculations here…
#to:
def init( self, SentInstance):
Thread.init(self)
#…
self.start()
def run(self):
… calculations here…
Thanks again
Roger
Problem resolved:
I found out that the plt.close() doesn’t truly close out the figures unless there is a
plt.ion() prior to the first usage of plt. This sets the interactive mode on.
Now I set up the calculations and plotting module as a Thread. Usage of a Thread clears up the GUI Freeze/white out issues.
And within the calculations/plotting module I use the plt.ion() and plt.close(‘all’) to allow the plotting to work on second and all subsequent calls to it.
Roger
···
On Saturday, April 6, 2013 7:52:28 PM UTC-6, Roger Zimmerman wrote:
Hi Mike and All,
Well, I may have spoken a little to soon on this fix :\
The GUI lockup/blanking issues is cleared up fine. But a new problem surfaced.
From the GUI I run the thread that does the calculations. If I run the calculations twice, the GUI continues to work fine, but the thread freezes.
I am using matplotlib.pyplot to plot the data, and saving plots to files using savefig. So I never show() the plots.
The thread freezes on the second pass through as it is trying to create the figure on this line:
plt.figure(0,figsize = (5,5), dpi = 300))
I also have a line:
plt.close(‘all’)
which I believe should close out the plot after each pass.
Oddly, I close and create the figure a few times within the thread. And this works fine. But on the second pass to the Thread it locks up the first time I try to create a figure.
I also tried the code using multiprocessing, that caused the GUI lockup/blanking issue, but fixed the freeze on second pass issue :[
Any suggestions are appreciated.
Thanks
Roger
On Wednesday, April 3, 2013 4:29:05 PM UTC-6, Roger Zimmerman wrote:
Hi Mike,
Thanks a million for the threading suggestion! Threading fixed the problem. Now my application runs smooth and doesn’t blank out or go ‘Not Responding’ even if I use other applications at the same time.
Thanks for your tutorial on thread safe wx. I will implement that later to be able to communicate back to main from the thread. So far I just changed the ‘Calculations’ module to a thread, that self runs when called from main. Here are all the changes I had to make to get it to work as a thread:
#add the import
from threading import Thread
#changed from:
class CalculatorClass:
#to:
class CalculatorClass(Thread):
#change from:
def init( self, SentInstance):
…
def CalculationClass(self):
… calculations here…
#to:
def init( self, SentInstance):
Thread.init(self)
#…
self.start()
def run(self):
… calculations here…
Thanks again
Roger
IIUC, you are using M{PL to generate plots all in memory, then saving
to PNG. And all this inside a wx app.
If so, I'd stay away from most of the pyplot machinery -- it is a
state machine that is more or less designed to support interactive
use. INstead, use the MPL OO interface directly, then you can control
the creation, destruction, etc of figures just the way you need.
A little discussion of the issues is here:
http://matplotlib.org/faq/usage_faq.html#coding-styles
HTH,
-Chris
···
On Mon, Apr 8, 2013 at 12:34 PM, Roger Zimmerman <roger.zimmerman@gmail.com> wrote:
I found out that the plt.close() doesn't truly close out the figures unless
there is a
plt.ion() prior to the first usage of plt. This sets the interactive mode
on.
--
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.Barker@noaa.gov