LWN.net Logo

Advertisement

Advanced thin client solution for Linux, based on Open Source. Mix Windows and Linux, with hardware accelerated OpenGL!

Advertise here

Various notes, all about Python

Dave Jones's How user space sucks talk at OLS this year received quite a bit of attention. It is simultaneously discouraging and encouraging to know that so many of our applications behave as inefficiently as they do. Discouraging because we should be doing better than that; encouraging because there are obviously easy fixes to be made.

Jeff Waugh recently brought back memories of that talk with a weblog entry on how Python behaves. For the curious: start up an interactive Python interpreter, then examine it from another window with strace. That Python interpreter, seemingly doing nothing, is, in fact, busily waking up ten times per second so that it can do nothing in a more active way. The offending code (in the readline library) is easy to find; it wakes up every 100ms just in case somebody might have registered a hook to look for events outside of the input file descriptor. As it turns out, the Python GTK library does the same thing so that it can check for pending signals.

So a system running a number of Python GTK applications (and some systems have many) will be experiencing the load of each one of them doing nothing every 100ms. This sort of behavior uses CPU time needlessly and it keeps the processor from sleeping - thus draining laptop batteries more quickly. Not good behavior - and a bit of low-hanging fruit that, one hopes will get fixed in the near future.

Meanwhile, the Python developers are working toward a major new release with the first Python 2.5 release candidate in testing for the last few weeks. For a full description of what's in Python 2.5, see A.M. Kuchling's excellent summary. New language features include conditional expressions (something like the "? :" notation used in C, but with a very different syntax), partial function application (forms of functions with some of the arguments supplied ahead of time), a number of exception handling improvements, a "with" statement intended to provide robust cleanup handling, and a number of performance improvements. There is also a long list of new modules and enhancements to existing modules.

The Python developers have long talked, often not entirely seriously, about "Python 3000," the upcoming major update to the language. While the Python language has evolved considerably over the 2.x series, it has done so in a compatible manner - older Python programs continue to run (though Python extensions written in other languages have tended to break). With Python 3000, the plan is that anything can happen, and there will be no guarantee (or even, perhaps, hope) that unmodified Python 2.x programs will work.

Python 3000 has been, as they say, Py in the sky for some time. But it looks like that situation might change before too long; some serious plans for the Python 3000 series have been laid down, and development may happen soon. Very soon, according to Python benevolent dictator for life Guido van Rossum:

We are now officially starting parallel development of 2.6 and 3.0. I really don't expect that we'll be able to merge the easily into the 3.0 branch much longer, so effectively 3.0 will be a fork of 2.5.

He goes on to suggest that much of the work for Python 2.6 may be oriented toward helping programs (and programmers) make the jump to the eventual 3000 release. So Python 2.6 may not contain a whole lot of new features, but it could have a bunch of new warnings for things that will break in the future - and fixes to the standard modules to avoid those warnings.

The first alpha Python 3000 release is expected sometime next year; it could be a year or so after that before the stable release (to be Python 3.0) is ready. Current plans are to continue to develop and support 2.x for some time - well into the 3.x series.

What will be in Python 3000 3.0? Python Enhancement Proposal 3100 has the details, as they are understood at the moment. These include the removal of old-style classes, various expression syntax changes, a new set syntax, use of Unicode throughout (but no non-ASCII characters used in the language itself), and much more.

Python hackers who are concerned about changes to the language might want to take a look at PEP 3099, a document listing the things that will not change. These include no implicit self, no programmable syntax, no overly complex parser, and so on. There will be no braces added in Python 3.0, preserving the grouping by indentation that is such a strong characteristic of the language; for some amusement, fire up Python and type:

    from __future__ import braces

In the end, for all its changes, the Python language will still be very much true to its original goals: a straightforward language with one clear way to carry out most tasks. Python 3.0 will also be developed in an evolutionary manner - no massive rewrite or multi-year series of pronouncements from the language designer. As a result, Python 3.0 should, despite its rather later start, be in use well before Perl 6.

Finally, for a different and interesting project, PyPy is worth a look. These developers are writing an entirely new Python interpreter - in Python. There are a lot of goals driving this work, one of which is the ability to compile the interpreter into a runtime system which is highly targeted for its intended purpose. Different builds can use different memory management algorithms, for example. The developers believe that they will eventually be able to build Python systems which run faster than the current C interpreter - though, at this point, they are running about three times slower. It is an active project, however, which is making rapid progress; expect interesting things from that direction.


(Log in to post comments)

Perl 6

Posted Sep 6, 2006 21:50 UTC (Wed) by cventers (subscriber, #31465) [Link]

I don't think this Perl 6 - Python 3000 race has already been decided.
From what I've been hearing, we may see an 'alpha' official Perl 6
release this year, and Pugs and Python have been tearing forward at
amazing speed lately. Perl 6 also has the benefit that there are now real
applications ported to and running on Pugs today.

It will be an interesting competition, but in the end, Perl and Python
developers may be shocked to find themselves using eachother's modules
underneath the Parrot runtime. :)

Perl 6

Posted Sep 7, 2006 2:35 UTC (Thu) by pphaneuf (subscriber, #23480) [Link]

That would be pretty cool, to have the two unify their runtimes in that way, actually!

Tim Bray was talking about that recently (look at the "Integration" paragraph at the bottom). I'd tend to agree with his assessment.

Various notes, all about Python

Posted Sep 7, 2006 1:24 UTC (Thu) by pcdavid (subscriber, #4295) [Link]

Google has a 1 hour video of Guido talking about Python 3000, as part of the google Tech Talks series: http://video.google.com/videoplay?docid=-6459339159268485356

Various notes, all about Python

Posted Sep 7, 2006 1:42 UTC (Thu) by fwenzel (guest, #33783) [Link]

When they say "partial function application", do they mean Currying?

Various notes, all about Python

Posted Sep 7, 2006 8:26 UTC (Thu) by Wummel (subscriber, #7591) [Link]

Yes, partial() implements currying. Currying was possible before with the lambda operator, but partial() also allows keyword arguments, plus not all like the lambda operator in Python :)
See also PEP 309.

Various notes, all about Python

Posted Sep 7, 2006 8:59 UTC (Thu) by fwenzel (guest, #33783) [Link]

Ah, thanks a bunch for the link :)

Various notes, all about Python

Posted Sep 7, 2006 10:23 UTC (Thu) by AJWM (subscriber, #15888) [Link]

> Currying was possible before with the lambda operator,

Making a nice lamb curry, no doubt.

(Sorry, that was bad, but it's almost lunchtime...)

Various notes, all about Python

Posted Sep 7, 2006 2:38 UTC (Thu) by pphaneuf (subscriber, #23480) [Link]

Polling every 100 millisecond for a signal is truly appalling, as this problem has been solved a long time ago (write a byte to a pipe in the signal handler, putting the other end in the select() interest set). Now, please, stop waking up my computer.

Various notes, all about Python

Posted Sep 7, 2006 9:07 UTC (Thu) by nix (subscriber, #2304) [Link]

Nick Mclaren has a large number of posts in the thread this article
references saying this can't be done: but since those threads basically
boil down to 'all existing OSes, including Linux, have bugs in this area,
and tracking them down is so hard that only I in all the world can do it,
we have fallen from an ancient golden age when this stuff worked', I'm not
inclined to pay much attention. (Argument from authority doesn't work,
guys, especially not if you refer to similar bugs in things like TCP/IP
which have 'gone unfixed for decades' and then *don't provide enough
information to allow anyone else to find out what those bugs are*...)

Various notes, all about Python

Posted Sep 7, 2006 3:11 UTC (Thu) by dale77 (subscriber, #1490) [Link]

Hmmm. An interesting experiment to try @ home.

dale@gordon:~$ python
Python 2.4.3 (#1, May 13 2006, 20:51:04)
[GCC 4.0.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

dale@gordon:~/blfs-sources/strace-4.5.14$ strace -p $(pidof python)
Process 7611 attached - interrupt to quit
read(0,

Um. Excuse me, its just sittin' there. No 10 wakes per second on this box.
Perhaps it's because I built it myself, rather than running RedHat? Is my
build broken because my python appears not to suck?

What's up?

Dale

Various notes, all about Python

Posted Sep 7, 2006 3:50 UTC (Thu) by cortana (subscriber, #24596) [Link]

Possibly. I just tried it on my Debian machine and observed a constant stream of select system calls.

Various notes, all about Python

Posted Sep 7, 2006 3:52 UTC (Thu) by nduboc (subscriber, #23707) [Link]

I tested on my Debian testing/unstable box and reproduce the select flood with python2.4 but not with python2.3.

--
Nico

Various notes, all about Python

Posted Sep 7, 2006 4:15 UTC (Thu) by dale77 (subscriber, #1490) [Link]

I suppose the fact that it seems to be good on my LFS system could be due
to a fix in readline for LFS. When you build LFS the readline source is
patched, as the LFS book says:

Upstream developers have fixed several issues since the initial release of
Readline-5.1. Apply those fixes:
patch -Np1 -i ../readline-5.1-fixes-3.patch

Dale

Various notes, all about Python

Posted Sep 7, 2006 4:23 UTC (Thu) by shane (subscriber, #3335) [Link]

The article indicates that the problem is from the readline library. If
your Python is not complied with the readline library, you would not see
this behavior.

A simple test would be to hit "ctrl-R" and see if the interpreter asks for
a "reverse-i-search". If it does, then you are using readline, if not,
then probably not.

Various notes, all about Python

Posted Sep 7, 2006 4:34 UTC (Thu) by dale77 (subscriber, #1490) [Link]

Ctrl-R reports (reverse-i-search) so on your authority readline appears to
be in there. As expected really, because python is not part of the base
LFS build, while readline is.

Dale

Various notes, all about Python

Posted Sep 7, 2006 6:34 UTC (Thu) by Dom2 (guest, #458) [Link]

Is your version of python built with threading turned on? If not, you probably won't see it.

Various notes, all about Python

Posted Sep 8, 2006 4:19 UTC (Fri) by dale77 (subscriber, #1490) [Link]

I would have built it like this:

./configure --prefix=/usr --enable-shared &&
make

Various notes, all about Python

Posted Sep 7, 2006 7:33 UTC (Thu) by amk (subscriber, #19) [Link]

See the Python bug report. The select() code is only used with readline 2.1; more recent versions of readline use different interface code.

Various notes, all about Python

Posted Sep 14, 2006 12:00 UTC (Thu) by dag- (subscriber, #30207) [Link]

The Red Hat bugzilla report Jeff Waugh refered to, is not related to his findings of the python interactive shell.

In fact, Fedora or Red Hat (at least since Red Hat 7.2) do not have the readline <= 2.1 related problem Jeff found. Even Red Hat 7.2 comes with readline 4.2.

So Red Hat or Fedora is not affected by this 100ms wake-up issue, so maybe Python *is* ready for the enterprise, but Jeff's distribution is not ? :-)

Only while interactive

Posted Sep 7, 2006 8:36 UTC (Thu) by nas (subscriber, #17) [Link]

Note that it only polls when sitting in the readline interactive prompt. Try strace python -c 'while True: pass'. The bug should and will be fixed but this is hardly a major problem.

An Incoherent Summary

Posted Sep 14, 2006 4:47 UTC (Thu) by jfj (guest, #37917) [Link]

An article by somebody at OLS. That may be related to somebody's blog and some technical data of polling file descriptos and signals. The author then jumps with a "Meanwhile" statement into the current state of 2.5, the release candidate of the week, and 2 features that have been added to the language. Then, we are informed about Python 3000, which was a joke, but it's started and there are various suggestions about how to break backwards compatibility, and yet ease the transition. The author just discovered what happened after he typed "from future import braces". In the end, unlike bad perl6 python will continue to be what it was. And finally there is pypy, which is an interesting addition to the article because many things can happen.

Copyright © 2006, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds