From: Fernando P. <Fer...@co...> - 2004-09-30 23:34:15
|
Hey John, I've added code to ipython to wrap use() to prevent users from switching backends interactively, since this will instantly crash things badly. It's a nice example of how python's dynamic nature allows you to tweak a module from the outside, without having to poke at its source. I now see could have done this for the show() problem as well, since it's essentially the same logic, so I shouldn't really have bothered you with source changes to the backends. Well, at least it was done in a generic way and not slapping code all over many files... With this safety in place, I tried running ALL the examples in 0.63 to see how we fare. I compiled some notes along the way, here they are for your (and other user's) reference. I think we're doing pretty good, except that people can always kill themselves by running true WX/GTK apps via @run. IPython is really not made for this, it can only handle gracefully show() calls from pure matplotlib scripts, not full-blown GUI apps. But I think we have a very reasonable environment at this point for most usage cases. Cheers, f ############################################################################# matplotlib examples under iypthon -pylab ---------------------------------------- I ran all the examples in mpl 0.63 with ipython (CVS from Sept 29/04, post 0.6.4.rc1). This was done using 'run foo.py', to see how robust this is. Most examples run fine, and leave ipython usable afterwards. Those listed below had some type of problem. Platform notes: Fedora core 2, python 2.3.3, Numeric 23.5, matplotlib 0.63 compiled only with Numeric (no numarray) support. // These don't run with LANG==de_DE.UTF-8, but are OK with en_US.UTF-8 run date_demo_convert.py run date_demo1.py run date_demo2.py run date_demo_rrule.py run finance_demo.py // these two run but segfault on exit under ipython. They run OK from a cmd line. run dynamic_demo_wx.py # this one runs, segfaults on exit run dynamic_image_wxagg.py # this one runs, segfaults on exit // OK with GTKAgg backend. It needs a use('GTKAgg') call to be safe for other backends. run dynamic_image_gtkagg.py # // these are OK with gtkagg, but they segfault wxagg. The segfault happens from a normal command line as well (no ipython). run system_monitor.py run dynamic_demo.py // these block ipython/pylab - any embedded true Wx/gtk stuff will kill ipython badly. What should we do here? run print_stdout.py run object_picker.py run embedding_in_gtk2.py run embedding_in_gtk.py run embedding_in_tk.py run embedding_in_wx.py run embedding_in_wx2.py run embedding_in_wx3.py run embedding_in_wx4.py run mpl_with_glade.py // other errors (not ipython related) ****run ftface_props.py --------------------------------------------------------------------------- SystemError Traceback (most recent call last) /home/fperez/code/python/pylab/examples/ftface_props.py 68 print 'Mult. masters :', font.style_flags & FT_FACE_FLAG_MULTIPLE_MASTERS != 0 69 print 'Glyph names :', font.style_flags & FT_FACE_FLAG_GLYPH_NAMES != 0 70 ---> 71 font.jdh = 'hi' 72 print dir(font) SystemError: error return without exception set WARNING: Failure executing file: <ftface_props.py> ****run movie_demo.py: with WX backend it doesn't make the .png frames at all with WXAgg, it runs fine but fails to make the movie: ... Saving frame _tmp049.png Making movie animation.mpg - this make take a while sh: line 1: mpeg2encode: command not found convert: Delegate failed (mpeg2encode "%i" "%o"). convert: Delegate failed (mpeg2encode "%i" "%o") [No such file or directory]. Symlinking mpeg2encode to mpeg2enc (the real binary) doesn't help, a different error comes back. I got it to work by commenting out the convert call and reverting to the mencoder one. Great! ****run vertical_ticklabels.py --------------------------------------------------------------------------- NameError Traceback (most recent call last) /home/fperez/code/python/pylab/examples/vertical_ticklabels.py 3 4 plot([1,2,3,4], [1,4,9,16]) 5 xticks([1,2,3,4], ['Frogs', 'Hogs', 'Bogs', 'Slogs']) ----> 6 set(t, 'rotation', 'vertical') 7 show() NameError: name 't' is not defined WARNING: Failure executing file: <vertical_ticklabels.py> |
From: John H. <jdh...@ac...> - 2004-10-01 14:10:53
|
>>>>> "Fernando" == Fernando Perez <Fer...@co...> writes: Fernando> I think we're doing pretty good, except that people can Fernando> always kill themselves by running true WX/GTK apps via Fernando> @run. IPython is really not made for this, it can only Fernando> handle gracefully show() calls from pure matplotlib Fernando> scripts, not full-blown GUI apps. But I think we have a Fernando> very reasonable environment at this point for most usage Fernando> cases. It's looks like about 90% of your problems result from trying to cross GUI backends within IPython. Is this fair to say? As far as I'm concerned I don't have a problem with these cases. Caveat emptor -- the user should be forewarned and expect disaster if they try and run GUI specific examples from ipython. Perhaps you should say pylab only supports pure matlab interface matplotlib at this point. From your end I see why it's a concern - you don't want any run command to break or freeze ipython. If you have any ideas on what we should do I'll be happy to help on the matplotlib end, but I don't have any off the top of my head. I'll comment on some of the non cross-GUI problems below.... Fernando> // These don't run with LANG==de_DE.UTF-8, but are OK Fernando> with en_US.UTF-8 run date_demo_convert.py run Fernando> date_demo1.py run date_demo2.py run date_demo_rrule.py Fernando> run finance_demo.py Do they run from the shell with LANG==de_DE.UTF-8? Any idea what is going wrong? Fernando> run print_stdout.py This is an example script to show how to print png to stdout from agg. Perhaps this fails because ipython doesn't really expect a png coming in from stdout? The header of that file states # print png to standard out # usage: python print_stdout.py > somefile.png Fernando> ****run ftface_props.py ---> 71 font.jdh = 'hi' I was testing to see if I could setattr on my extension class. I'll just remove this line from the example Fernando> ****run movie_demo.py: with WX backend it doesn't make Fernando> the .png frames at all with WXAgg, it runs fine but Fernando> fails to make the movie: ... Saving frame _tmp049.png Fernando> Making movie animation.mpg - this make take a while sh: Fernando> line 1: mpeg2encode: command not found convert: Delegate Fernando> failed (mpeg2encode "%i" "%o"). convert: Delegate Fernando> failed (mpeg2encode "%i" "%o") [No such file or Fernando> directory]. Fernando> Symlinking mpeg2encode to mpeg2enc (the real binary) Fernando> doesn't help, a different error comes back. Fernando> I got it to work by commenting out the convert call and Fernando> reverting to the mencoder one. Great! Yes, this fails on my system too. This line works os.system("convert _tmp*.png animation.mpg") but I wasn't able to get convert to make mpg. I'll fixed this in the examples dir and made the mencoder line the default. Fernando> ****run vertical_ticklabels.py Fernando> --------------------------------------------------------------------------- Fernando> NameError Traceback (most recent call last) Fernando> /home/fperez/code/python/pylab/examples/vertical_ticklabels.py Fernando> 3 4 plot([1,2,3,4], [1,4,9,16]) 5 xticks([1,2,3,4], Fernando> ['Frogs', 'Hogs', 'Bogs', 'Slogs']) ----> 6 set(t, 'rotation', 'vertical') Fernando> 7 show() Fernando> NameError: name 't' is not defined WARNING: Failure Fernando> executing file: <vertical_ticklabels.py> Fixed. This also pointed me a bug in the new commands xticks and yticks; they weren't returning the things they claimed in the doc string. Thanks for the detailed notes. JDH |
From: Fernando P. <Fer...@co...> - 2004-10-01 16:40:12
|
John Hunter schrieb: >>>>>>"Fernando" =3D=3D Fernando Perez <Fer...@co...> writ= es: >=20 >=20 > Fernando> I think we're doing pretty good, except that people can > Fernando> always kill themselves by running true WX/GTK apps via > Fernando> @run. IPython is really not made for this, it can only > Fernando> handle gracefully show() calls from pure matplotlib > Fernando> scripts, not full-blown GUI apps. But I think we have a > Fernando> very reasonable environment at this point for most usage > Fernando> cases. >=20 > It's looks like about 90% of your problems result from trying to cross > GUI backends within IPython. Is this fair to say? Well, not quite. As I mentioned, I put in a matplotlib.use() wrapper whi= ch=20 traps invalid switches, so it's not a problem if a use() call is made. C= ould=20 you add such a call to this one please? : // OK with GTKAgg backend. It needs a use('GTKAgg') call to be safe for o= ther backends. run dynamic_image_gtkagg.py It's only when native GUI examples are run that things crash badly. Note= that=20 some of the segfaults occur from plain python: // these are OK with gtkagg, but they segfault wxagg. The segfault happe= ns from a normal command line as well (no ipython). run system_monitor.py run dynamic_demo.py And I also have these: // these two run but segfault on exit under ipython. They run OK from a = cmd line. run dynamic_demo_wx.py run dynamic_image_wxagg.py I suspect these two are messing something up badly enough that if python = quits=20 right away, you don't see the problem, but since ipython continues to run= the=20 interpreter, the problem appears. Since these are segfaults, I'm very mu= ch=20 willing to blame the wx code in there, and not ipython (which is 100% pur= e,=20 unpolluted python :) > As far as I'm concerned I don't have a problem with these cases. > Caveat emptor -- the user should be forewarned and expect disaster if > they try and run GUI specific examples from ipython. Perhaps you > should say pylab only supports pure matlab interface matplotlib at > this point. >=20 >>From your end I see why it's a concern - you don't want any run > command to break or freeze ipython. If you have any ideas on what we > should do I'll be happy to help on the matplotlib end, but I don't > have any off the top of my head. Yes, this is the real nasty. If you think that the ipython+matplotlib=20 combination is going to be a common one in the future for scientists, it = may=20 be worth protecting the examples against disaster (given they tend to be = what=20 people run to first). If you are willing to pay the price of 12 lines of= code=20 per example, you could put this snippet at the beginning of _every_ embed= ded=20 example: # Detect if we are inside IPython and bail if so. Threading problems # make it very difficult to safely run full GTK/WX apps inside IPython. try: __IPYTHON__ msg =3D ("This script can NOT be run inside IPython.\n\n" "It embeds matplotlib into a complete GUI application, and\n" "for a number of reasons this is (and probably will remain)\n= " "unsupported from inside IPython.\n\n" "You can run it from the command line as a regular python scr= ipt.\n") raise RuntimeError,msg except NameError: pass This will make sure that users get a meaningful error message inside ipyt= hon=20 instead of a bizarre lockup or segfault. > I'll comment on some of the non cross-GUI problems below.... >=20 > Fernando> // These don't run with LANG=3D=3Dde_DE.UTF-8, but are OK > Fernando> with en_US.UTF-8 run date_demo_convert.py run > Fernando> date_demo1.py run date_demo2.py run date_demo_rrule.py > Fernando> run finance_demo.py >=20 > Do they run from the shell with LANG=3D=3Dde_DE.UTF-8? Any idea what i= s > going wrong? Yes, the problem has nothing to do with ipython, it also happens with pla= in=20 python. Note that the broken ones are: // These don't run with LANG=3D=3Dde_DE.UTF-8, but are OK with en_US.UTF-= 8 run date_demo1.py run date_demo2.py run finance_demo.py I think my original list had more by mistake. Here's a traceback (form=20 ipython, so you get better details): In [5]: run date_demo1.py -------------------------------------------------------------------------= -- ValueError Traceback (most recent call las= t) /home/fperez/code/python/pylab/examples/date_demo1.py 26 yearsFmt =3D DateFormatter('%Y') 27 ---> 28 quotes =3D quotes_historical_yahoo( 29 'INTC', date1, date2) 30 if not quotes: /usr/local/lib/python2.3/site-packages/matplotlib/finance.py in=20 quotes_historical_yahoo(ticker, date1, date2) 61 if len(vals)!=3D7: continue 62 datestr =3D vals[0] ---> 63 dt =3D datetime.date(*time.strptime(datestr, '%d-%b-%y')[= :3]) 64 d =3D date2num(dt) 65 open, high, low, close =3D [float(val) for val in vals[= 1:5]] /usr/src/build/394694-i386/install/usr/lib/python2.3/_strptime.py in=20 strptime(data_string, format) 422 found =3D format_regex.match(data_string) 423 if not found: --> 424 raise ValueError("time data did not match format: data=3D= %s=20 fmt=3D%s" % 425 (data_string, format)) 426 if len(data_string) !=3D found.end(): ValueError: time data did not match format: data=3D31-Mar-04 fmt=3D%d-%= b-%y WARNING: Failure executing file: <date_demo1.py> The problem is that under different locales, dates come out formatted=20 differently. You seem to have hardcoded format expectations which break = in=20 the face of non-US locales. > Fernando> run print_stdout.py >=20 > This is an example script to show how to print png to stdout from agg. > Perhaps this fails because ipython doesn't really expect a png coming > in from stdout? The header of that file states Well, running it again I'm getting this: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/src/build/394694-i386/install/usr/lib/python2.3/threading.p= y",=20 line 436, in __bootstrap self.run() File "/home/fperez/code/python/IPython/Shell.py", line 527, in run self.IP.mainloop() File "/home/fperez/code/python/IPython/iplib.py", line 948, in mainloo= p self.interact(banner) File "/home/fperez/code/python/IPython/iplib.py", line 1036, in intera= ct line =3D self.raw_input(prompt) File "/home/fperez/code/python/IPython/iplib.py", line 1263, in raw_in= put return self.prefilter(raw_input(prompt), IOError: [Errno 9] Ung=FCltiger Dateideskriptor Pehaps you could add (if you decide that you like that idea) the __IPYTHO= N__=20 trap code to this as well, so that all examples are made ipython-friendly= . In=20 this one, the message could additionally show this: print png to standard out usage: python print_stdout.py > somefile.png so users know what to do straight away. > Thanks for the detailed notes. No prob. I'm a big believer that good examples are what helps most new u= sers,=20 so I'm trying to make sure that out-of-the-box, things run as smoothly as= =20 possible for all those scientists who are just dying to start using matpl= otlib=20 with ipython :) Best, f |