Thursday, July 28, 2005

MochiKit 0.5

MochiKit is a platform-agnostic javascript framework that doesn't suck. (Here's the release announcement, following the announcement of a public subversion repository a few days ago.) The documentation alone should make MochiKit the preferred js library. It's a huge improvement over the alternatives.

Bob Ippolito has been working on MochiKit for a while. I've learned a lot from his javascript blog posts as he's worked on it. If you think you know javascript, but don't know what a prototype is (I didn't), you need to read his blog.

(Yes, Bob knows about JSoLait and Prototype. He doesn't like them, and gives excellent reasons for the genesis of MochiKit.)

Wednesday, July 27, 2005

iXP

I love Mike Spille's blog. He doesn't post terribly often, but when he does it's always worth reading. Here he is with a savagely funny mock of XP.

Rule 0. Whenever you type an 'i' - drink!. Also known as the zeroeth iXP rule. While the vision began with Alternate Letter Pair Programming Order, mentioned below, it's really this rule that made iXP gel, and which differentiated it from previous similar practices.

Thursday, July 21, 2005

Spyce testimonials

Since the Daily Python URL was kind enough to link to the 2.0.3 announcement, I thought a few testimonials might be in order. :)
I tried downloading, installing and using Spyce 2.0.2 on Windows and Linux yesterday and it worked like a dream. I have already set up a useful little dynamic site on a linux box and plan to expand it radically in the weeks ahead. I am using Spyce in webserver mode and also using the scheduler to trigger periodic repository updates.
    --Rock Howard
Spyce is really speeding up my "project"... at this rate, I'll be ready for pre-beta testing in about two months. I'm utterly addicted to encapsulation via active tags.
    --Tim Lesher
(Not to pick on them since they do have a nice framework, but Tim was formerly using CherryPy. Most recently, anyway.)

Spyce 2.0.3 released

2.0.3 is a bugfix and documentation-improvement release. The installation section of the manual has received particular attention. There is also the new section on starting your first project, which answers the FAQ, "how do I organize my Spyce files?"

Changelog:

    - fix pool bug if server not in concurrency=threaded mode; reported by "Dude"
    - documentation improvements
    - avoid stomping on user python modules named 'config'; reported by Betty Li
    - (John Reese) fixed bad interaction of "redirect if directory path doesn't 
      end in /" and "look for default index.$[index extensions] files" code
      in Spyce webserver
    - default concurrency mode for Spyce webserver is 'threading' instead of None
    - spyceProject script to automate new-project creation

Update: you may also be interested in the new testimonials post.

Wednesday, July 20, 2005

on Broken Pipe and Connection Reset By Peer

Maybe I'm just dumb, but I always thought "broken pipe" meant, "the other end of this socket closed before I finished sending something" and "connection reset by peer" meant, well, roughly the same thing. (As well as indicating some slightly more esoteric problems.)
Turns out though, "broken pipe" actually means "I just tried to send something and the socket was already closed to sending."
So in the following example, if the other end of (TCP) socket "sock" closes or dies before the write method, "connection reset by peer" will be raised. The next write will give a broken-pipe error, since the socket now knows that further sending is invalid.
try:
    sock.write('foo')
except:
    pass # connection reset by peer
sock.write('bar') # broken pipe


Sunday, July 17, 2005

Jython is back

After almost two years with no releases, Brian Zimmer has released an alpha version of Jython 2.2 (incorporating some of the patches I submitted back in Jan 04). Ha!

Brian, you will recall, got a PSF grant for Jython and started work earlier this year. Obviously his original estimate called for a much faster release, but that's how software development goes. Six months to a release after inheriting a new-style class branch that I suspect was mostly broken really isn't too shabby, especially considering how long it took the CPython team.

I haven't been following Jython development since I gave up hope of Samuele Pedroni ever getting a release out last year, but it's clear that Jython isn't a one man show anymore. Frank Wierzbicki and Clark Updike have been comitting code; almost certaintly there are others too that I didn't immediately notice. Frank and Clark have both been involved with Jython for a while, but new developers are getting involved too. Good to see.

Big thumbs up to all involved.

Wednesday, July 13, 2005

How well do you know python, part 8

Here is a mostly-functioning class that facilitates writing producer / consumer algorithms. It is designed to support a single producing and multiple consuming threads, i.e., scenarios where consuming involves some blocking operations such as communicating over a socket.

"Mostly," in this case, means that there are two bugs in this class that can be fixed in a total of four or five lines. One is arguably more subtle than the other, but they involve the same part of the code. Can you spot them?

Warning: this one is tougher than part 2, which also dealt with threading.

import Queue as queue
import threading

class PCQueue:
    def __init__(self, initialthreads):
        self.q = queue.Queue()
        self.running = True
        self.condition = threading.Condition()
        for i in range(initialthreads):
            self.add_consumer()
    def run_consumer(self):
        while True:
            self.condition.acquire()
            try:
                self.condition.wait()
                if not self.running:
                    return
            finally:
                self.condition.release()
            obj = self.q.get()
            self.consume(obj)
    def put(self, obj):
        self.condition.acquire()
        self.q.put(obj)
        self.condition.notify()
        self.condition.release()
    def consume(self, obj):
        raise 'must implement consume method'
    def add_consumer(self):
        threading.Thread(target=self.run_consumer).start()
    def stop(self):
        self.running = False
        self.condition.acquire()
        self.condition.notifyAll()
        self.condition.release()

Here's a short example using PCQueue.

class PCExample(PCQueue):
    def consume(self, url):
        import urllib
        n = len(urllib.urlopen(url).read())
        print '\t%s contains %d bytes' % (url, n)

q = PCExample(2) # 2 threads
while True:
    print 'url? (empty string to quit)'
    url = raw_input()
    if not url:
        break
    q.put(url)
q.stop()

Friday, July 01, 2005

Two Wax projects for Summer of Code

The PSF put up a list of projects accepted for Google's Summer of Code. Not one, but two projects deal with improving Hans Nowak's Wax toolkit. Very cool: hopefully by the time I have to write another desktop-bound application, Wax will be mature and well-documented. Tkinter is too underpowered, and wx is too clunky.

That's why I added Wax to the SoC coding project ideas wiki, although it wasn't immediately clear if this was welcome. Glad it worked out.

(Two people working on Wax is old news if you read Hans's blog. Which I haven't been, inexplicably. Ah, well.)