Skip to main content

Posts

Of all the things I've lost...

I installed a sys.excepthook in my project at work that uses the logging module to record any uncaught exceptions. It didn't work. I did what any lazy programmer would do: ask someone more experienced. "Do you have to set sys.excepthook in each thread?" I asked, more-or-less. "I don't think so," he replied. Hmm. Maybe the developer I'd taken over from was setting excepthook later on in the initialization or somewhere else. ... Nope. Finally I wrote this: import sys, threading def log_exception(*args): print 'got exception %s' % (args,) sys.excepthook = log_exception def foo(): a = 1 / 0 threading.Thread(target=foo).start() Playing with this a bit demonstrates that sys.excepthook doesn't work in subthreads, at all . The documentation doesn't mention anything of the sort. Smells like a bug to me. (I did file one .) I belatedly googled "sys.excepthook threads." (I must have been a bit slow this morning to no...

The tale of a wiki diff implementation

I run a web game that I started in late 2000, back in the Dark Ages before there was a decent python web toolkit. It runs on a then-current version of the OpenACS TCL-based toolkit. (at around 20kloc, porting it to a more modern system wouldn't be worth the effort now.) Recently, a player suggested that I add a wiki, since my own documentation is chronically out of date and player-run sites tend to suffer bitrot as well. (How many games are you still playing that you started 5 years ago?) So, I backported a modern OpenACS wiki module -- no trivial task; a LOT has changed in OpenACS, and not all for the better -- and was set. Except the module I backported didn't have diff functionality, probably because the various TCL options mostly suck . Enter TclPython , a tcl module by Jean-Luc Fontaine (who is obviously a far better C hacker than I) that embeds a python interpreter. Sweet! My life just got a lot easier: package require tclpython set py [python::interp new] #...

SF.net examples fixed, again

This time I apparently broke it by copying the development spyceconf.py, which among other things references the authentication tag that doesn't exist in 2.0, into the sourceforge site. Oops. (The 2.0.2 release itself wasn't affected.)

I figured out why Python's threading library bugs me

Reading Aahz's 2001 OSCon presentation , I ran into a slide that crystalized it [paraphrased]: Perl: There's more than one way to do it Python: There should be one (preferably only one) obvious way to do it Python's threading library is philosophically perl-ish That pretty much says it all. Well, that and the main classes are (still) virtually undocumented. Update: I'm referring to the synchronization classes in this module, not the Thread class, which is straightforward enough.

Why PHP sucks

(July 8 2005) Apparently I got linked by some PHP sites, and while there were a few well-reasoned comments here I mostly just got people who only knew PHP reacting like I told them their firstborn was ugly. These people tended to give variants on one or more themes: All environments have warts, so PHP is no worse than anything else in this respect I can work around PHP's problems, ergo they are not really problems You aren't experienced enough in PHP to judge it yet As to the first, it is true that PHP is not alone in having warts. However, the lack of qualitative difference does not mean that the quantitative difference is insignificant. Similarly, problems can be worked around, but languages/environments designed by people with more foresight and, to put it bluntly, clue, simply don't make the kind of really boneheaded architecture mistakes that you can't help but run into on a daily baisis in PHP. Finally, as I noted in my original introduction, with PHP, ...

Anders Heljsberg doesn't grok Python

While Debian was releasing Sarge and Steve Jobs was introducing MacX86 yesterday, Anders Hejlsberg spoke on C# at Microsoft Tech-Ed . James Avery writes : After a couple questions from other people I was able to get in the other question I was dying to ask. What does Anders think about the resurgence in dynamic typing from languages like Python. Basically he said that he understands what benefits people are getting from dynamic typing, but he thinks they can get the benefits of dynamic typing without sacrificing strong typing. He talked about inferring type (what anonymous methods do now with delegates) and how that might be a way to get the coding speed and ease without sacrificing the strongly typed information. Unfortunately, omitting type declarations is only a small part of Python-esque dynamism. One of the smallest, in fact. Far more important are the ability to modify objects and classes at runtime, which allow you to do things in Python that would require code generation (w...

Spyce 2.0.2 released

Second bugfix release. Get it here . Changelog: session_dir uses config.tmp by default if no directory is specified fix for session_dir pickling on win32 fix for fileCache pickling bug on win32 reported by Jaros³aw Zabiello fix for sessions + handlers problem reported by Jonathan Taylor * all module init() methods are now run before handlers are called.

How well do you know Python, part 7

Given the following two classes, class A: def foo(self): print self.__class__.__name__ class B: pass why does this work, def bar(self): print self.__class__.__name__ B.foo = bar b = B() b.foo() while this does not? B.foo = A.foo b = B() b.foo()

Utah Python User Group

The former Provo-Orem Python Meetup Group is now the Utah Python User Group . I've set up a rudimentary website and discussion list; anyone interested in Python is welcome to join the list and/or attend the monthly meetings (next one on June 9th). (We're already on the user group wiki in case utahpython.org is hard to remember. :)

Spyce 2.0.1 released

Spyce 2.0.1 is available over at the usual place . This is a bugfix release. Changelog: use tempfile.gettempdir() as default config.tmp add originalsyspath to spyceconf bugfixes for Active Tag compiler portability & other bugfixes (John Reese)

Spyce vs ASP.NET

A former co-worker asked me over IM, What advantage, other than being able to use it on a Linux box, does [Spyce] have over the ASP.NET Model? Because I can tell you, with Visual Studio, I feel pretty productive. I answered, The main one is a significantly shallower learning curve. Once you know how the ASP.NET event model and page lifecyle work, you are set -- but you remember how "easy" that was for [our] students. With Spyce there is only one rule: handlers run before the rest of the page, in the order they were added. That's it. And, of course, Spyce runs Python. This is significant: Python is addictive; once you start writing code in it, it's painful to use less-expressive languages. This is something most people won't get until they try it, unless maybe they are old-school Lisp hackers. Now, Spyce isn't quite to the point where it matches ASP.NET feature for feature. But it's close, and getting closer. I checked in an authentication...

Microsoft ahead of Sun in dynamic language support

Microsoft's Chris Anderson writes : ...our singular focus on strongly typed compiled languages has blinded us to the amazing productivity and approachability of dynamic scripting langauges like Python and Ruby. I'm super excited that we are changing this. Hiring Jim Hugunin [to work on IronPython is a great start. Jython has long been the only Python (or any major dynamic language) implementation on a Big Platform VM, and it's still substantially more usable than IronPython despite months/years of languishing while Samuele Pedroni as the sole "active" project admin wrote little code and checked in less, much to the dismay of people who wanted to work on Jython. (Not that I'm bitter.) Now that Brian Zimmer got a PSF grant to work on Jython, thinks are finally moving again, slowly. But despite the moral support from Sun managers like Tim Bray, Sun really hasn't done much for dynamic languages on the JVM. Sure, they hoste...

Spyce 2.0 final

Spyce 2.0 is available here . "You've taken spyce off my 'disgusting template engines' list. This is how I'd want to see apps structured, exactly."     -- Tim Lesher "I feel easily five times as productive in Spyce as I do in JSP."     -- Conan Albrecht Spyce is a python web application server, combining the features of popular frameworks such as JSP and ASP.NET with Pythonic elegance. Spyce may be deployed as a standalone server (or proxied behind Apache), or under mod_python, FastCGI, or CGI. Documentation and demos are here . Highlights of Spyce 2.0 include: Active Handlers : reusable components without the leaky abstractions seen in ASP.NET et al. Active Tag compiler OpenACS-like (Tiles-ish, for you JSP people) parent/child layout system

Trial periods for software developers

Tim Lesher has an interesting post about applying meritocratic principles to hiring software developers . He suggestion is to hire developers as contractors for a trial period before taking them on full-time. If you as a hiring manager aren't sure about someone, either on a technical level or just fit with your team, this makes sense. I didn't have precisely this experience when I started as an instructor at Northface, but I did start at a lower salary with an explicit "if you're still here in 3 months, here's what your salary will rise to." (This was primarily because they wanted someone to teach ASP.NET, with which I had no experience at the time.) I thought this was a pretty fair approach, and much better than a rigid "if you don't have the right keywords on your resume, don't bother no matter how good you are." But companies won't bother giving the "maybe" candidates a trial period if they think they can find a "...

Materialized views in PostgreSQL

One thing I've wanted to write about for a while is materialized views in PostgreSQL. Materialized views are basically precomputed views; they're very very useful if you have an expensive query against data that doesn't change much. This is one of the tricks I use to keep the db overhead on Carnage Blender reasonable. Oracle and DB2 are the only RDBMS products that can auto-materialize views for you, but you can rig them yourself in PostgreSQL or anything that gives you a powerful enough trigger + procedural language. (And if performance is crucial, you'll end up hand-optimizing them in Oracle/DB2 as well. At least, back when I used Oracle in the 8.1 days.) But while looking for examples of a certain PL/PGSQL feature this morning, I found Jonathan Gardner's materialized views page (link may be down; see the archive.org copy ) which covers the subject so well that now I don't have anything left to add. Nicely done! Incidently, this is just one more reas...

Emacs support for Spyce

Committed spyce.el in svn contrib/. (For those of you not bound to it by 10+ years of habit, el stands for Emacs Lisp.) I didn't write a "spyce mode" per se; I just used the mmm-mode module to allow Emacs to recognize the python snippets inside html. mmm-mode is one of the most complex modules I've had to work with, and while it gets the job done, to me it seems like emacs is showing its age. Maybe one of the DrPython guys will write an Emacs keybinding package so I don't feel too lost. This is about as simple as you get with mmm-mode. You can get a lot more complicated . (require 'mmm-auto) (require 'mmm-sample) (setq mmm-global-mode 'maybe) (setq auto-mode-alist (cons '("\\.spy$" . html-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.spi$" . html-mode) auto-mode-alist)) (mmm-add-classes '((spyce1 :submode python-mode :front " ") (spyce2 :submode python-mode :front "...

Looks like spyce will have to find a new home

SF.net just sent out an email to project admins saying, among other things, that project web space will soon be mounted read-only. Bleh. That means I just wasted a LOT of time tweaking the Spyce makefile to auto-deploy to sf.net for no reason, because both of the new demos want to be able to write to disk. (One because it uses durus, and the other because since SF runs in CGI mode, the pool module pickles and unpickles itself to disk for each request. Which sucks rocks for performance, of course, but if you cared about that you wouldn't be using CGI, now would you?) Of course spyce.org is already taken by someone who isn't using it... I guess the bright side is now I can go ahead and enable comments on the Spyce documentation once it moves, if I have the time to wrestle with the TOC (table-of-contents) module to get it to spit out appropriate .spy files instead of html. (Making it into a wiki is another attractive option, but the nice thing about the TOC module is you ca...

"a new web framework named spyce"

Dion Almaer writes in a sort of footnote to his Python has a leg up in the dynamic language race post that [T]here is also word that a new web framework named spyce is going to try to do what Rails has done for Ruby. I think there are definitely some points of commonality if you take a big picture view; primarily, both are about leveraging the capabilities of dynamic languages to provide an environment vastly more productive than is possible with traditional staticly-typed-languages (Java, C#). How we go about that, though, is quite different. Spyce isn't trying to be a Rails clone a la Subway; it's its own beast. Spyce is more page-centric, like ASP.NET or OpenACS. Like all modern frameworks, Spyce encourages separation of code and markup, but it's not religious about forcing one man's vision of MVC down your throat. And while strictly speaking Dion is wrong to call Spyce "new," Spyce 2.0 has a much, much more modern feel to it than 1.x. If you evalua...

Spyce 2.0 beta released

Some 217 commits into development, Spyce 2.0 is finally available for download . The main Spyce site has been updated with the new docs, examples, and demos. Full changelog is here ; highlights include new-style active tags - docs OpenACS-like (Tiles-ish, for you JSP people) parent/child templating system - roughly the same speed as include.spyce, so using one parent template has about 1/2 the overhead as the old standard two-includes-for-header-and-footer. - docs Active Handlers reusable components without the leaky abstraction of ASP.NET et al. - docs The only major change since the prerelease was announced on this blog is that the class chunk token was changed from [[\\ to [[!. At least that's the only one I remember after spending the last 5 days wrestling with sourceforge's cgi-bin.