a question about backend, matplotlib and ipython

Hello,
I got a problem with backend in matplotlib.
I used ipython for launching the codes and
the backend of matplotlib is GTKAgg. I have a code.py with a for loop for processing data, and in each
iteration I read and plot and save the figures. Because there
are so many figures, I set the non-interative mode and not using “show()” in the code. Then the memory is used more and more as the
iteration number increases, and the most memory is
due to write_png function. I guess that the figures
(though not shown on the screen) from each iteration take the memory, and try to close the figures produced at each
iteration.
what I did:
modify the backend to Agg in the code
add “close(‘all’)” before each iteration finish.

         This works for removing the memory problem. But a new issue

arrive. After the run is finished, the ipython command window
has no response to any keyboard input for a few seconds, then a warning message appear:
“Warning: Timeout for mainloop thread exceeded switching to
nonthreaded mode (until mainloop wakes up again)”,
and when I tried to quit ipython afterwards, it is stuck there
and the ipython is crashed.
But if I tried using “python code.py” , then it works well : no warnings.
Does it mean that we can not use ipython and a backend non-GUI at the same time ?

Any one would like to explain a bit ? Thanks in advance !!

xiaoni

xiaoni,

For the way that you appear to be using ipython, it might be better to just use regular python instead. ipython is very useful for interactive systems and other advanced topics, but for a simple, loop-driven image generator, python will work just fine.

As for your memory usage, doing a clf() should be helpful to keep it under control. I should also note that ipython have been known to cause memory use to grow due to the extra references it holds to the figure data, although I don’t know if this is still true in the latest version that is currently being worked on.

I hope this helps,
Ben Root

···

On Mon, Aug 23, 2010 at 1:53 PM, xiaoni <wangxni@…9…> wrote:

Hello,
I got a problem with backend in matplotlib.
I used ipython for launching the codes and
the backend of matplotlib is GTKAgg. I have a code.py with a for loop for processing data, and in each
iteration I read and plot and save the figures. Because there
are so many figures, I set the non-interative mode and not using “show()” in the code. Then the memory is used more and more as the
iteration number increases, and the most memory is
due to write_png function. I guess that the figures
(though not shown on the screen) from each iteration take the memory, and try to close the figures produced at each
iteration.
what I did:
modify the backend to Agg in the code
add “close(‘all’)” before each iteration finish.

         This works for removing the memory problem. But a new issue

arrive. After the run is finished, the ipython command window
has no response to any keyboard input for a few seconds, then a warning message appear:
“Warning: Timeout for mainloop thread exceeded switching to
nonthreaded mode (until mainloop wakes up again)”,
and when I tried to quit ipython afterwards, it is stuck there
and the ipython is crashed.
But if I tried using “python code.py” , then it works well : no warnings.
Does it mean that we can not use ipython and a backend non-GUI at the same time ?

Any one would like to explain a bit ? Thanks in advance !!

xiaoni

Hello, Benjamin,
Thanks for your quick response ! I found that I only need use clf(), and then everything is fine ! The code can be run quickly and I can exit ipython gracefully afterwards. So it is not a problem of backend, just of clearing the existing figures properly ! (close() is not good because the figures are not displayed.)
cheers,
xiaoni

···

From: Benjamin Root <ben.root@…1304…>
To: xiaoni <wangxni@…9…>
Cc: matplotlib-users@lists.sourceforge.net
Sent: Tue, August 24, 2010 2:29:32 AM
Subject: Re: [Matplotlib-users] a question about backend, matplotlib and ipython

On Mon, Aug 23, 2010 at 1:53 PM, xiaoni <wangxni@…9…> wrote:

Hello,
I got a problem with backend in matplotlib.
I used ipython for launching the codes and
the backend of matplotlib is GTKAgg. I have a code.py with a for loop for processing data, and in each
iteration I read and plot and save the figures. Because there
are so many figures, I set the non-interative mode and not using “show()” in the code. Then the memory is used more and more as the
iteration number increases, and the most memory is
due to write_png function. I guess that the figures
(though not shown on the screen) from each iteration take the memory, and try to close the figures produced at each
iteration.
what I did:
modify the backend to Agg in the code
add “close(‘all’)” before each iteration finish.

         This works for removing the memory problem. But a new issue

arrive. After the run is finished, the ipython command window
has no response to any keyboard input for a few seconds, then a warning message appear:
“Warning: Timeout for mainloop thread exceeded switching to
nonthreaded mode (until mainloop wakes up again)”,
and when I tried to quit ipython afterwards, it is stuck there
and the ipython is crashed.
But if I tried using “python code.py” , then it works well : no warnings.
Does it mean that we can not use ipython and a backend non-GUI at the same time ?

Any one would like to explain a bit ? Thanks in advance !!

xiaoni

xiaoni,

For the way that you appear to be using ipython, it might be better to just use regular python instead. ipython is very useful for interactive systems and other advanced topics, but for a simple, loop-driven image generator, python will work just fine.

As for your memory usage, doing a clf() should be helpful to keep it under control. I should also note that ipython have been known to cause memory use to grow due to the extra references it holds to the figure data, although I don’t know if this is still true in the latest version that is currently being worked on.

I hope this helps,
Ben Root