| FeedSee | |
|
Ned Batchelder's blog Web Feed Ned Batchelder's blog I recently had need to run a piece of Python code before every invocation of the interpreter. In my case, it was to enable coverage testing of processes spawned by a test suite. Certain tests would run Python code in a subprocess, and I wanted to measure coverage within that process. I added a function to coverage.py that is suitable for executing on startup. It examines the environment to determine whether to start measuring coverage. (This code isn't released yet, but if you want to try it, it's on the trunk at bitbucket.) Perl has a command line switch (-M) for this, as does Ruby (-r), but Python doesn't. I came up with two ways to do it for Python, both depending on the site module which is imported automatically on startup. The first way is to create a sitecustomize.py file on the path somewhere. This module will be imported automatically by site.py. Any lines you add to that file are executed when Python starts: import coverage This is simple, but editing an existing sitecustomize.py could be awkward, and you may not even have permissions to do it. The second way is to create a .pth file with an executable line. Usually lines in .pth files are directory names, but if the line starts with "import " are executed (what a hack!), so you can create a .pth file like this: import coverage; coverage.process_startup() This has the advantage that you can create a new file without worrying about touching existing files, all .pth files will be examined and interpreted. Unfortunately, you might have to give the file a strange name, since they are executed alphabetically, and a package you need may only be available after its .pth file has been seen. In my case, I named my .pth file zzz_coverage_process_start.pth to be sure it ran after coverage was added to the path. Neither of these feels clean or elegant. I'm wondering if there are better techniques I'm overlooking? Python has a clean way to register functions to be called at process exit (atexit), which has been designed so that multiple authors of exit functions don't need to cooperate to avoid interfering with each other. It'd be nice to have a similar facility for startup functions. PyCon on the Charles, part 1 - The Cambridge Python Meetup will have a session next Wednesday, January 20. Three Boston-area PyCon speakers will be rehearsing their talks. PyCon 2010 is (as you must know) in Atlanta in February. This is a chance for speakers to practice and get some feedback to improve their talks. It's also a chance for Pythonistas who can't get to Atlanta to see some of the PyCon content. Heck, even if you are going to Atlanta, this is a way to resolve some of those "can't be in two places at once" problems at PyCon, which this year will have five parallel tracks! Full details and RSVP: PyCon on the Charles, part 1. There may even be snacks. Boston has six speakers this year, so part 2 will be on February 3: PyCon on the Charles, part 2. IE8's unpopular XSS filter - I've been struggling with the XSS filter in IE8. It seems capricious and secretive, and is getting in the way of an application we're running on AOL.com. I asked about it on stackoverflow, and got some more information, but still not enough to get it out of my hair. Anyone have any experience with this beast? Anne Leeds' dyslexia puzzle - Anne Leeds is a friend of mine from my years at Farm & Wilderness camps. We recently re-connected after 30 years (thank you, internet!) I remembered her as an energetic girl with an interest in graphic design, and was pleased to see that her essence had not changed over the years. We caught up, and it turns out that she also has a child with a disability, in her case, dyslexia. One of the things she did about it was to create a dyslexia puzzle: She describes it like this:
I love this: it's typographic, it's empathic, it's for kids, it's creative, it's dealing with a disability. It's got everything. D. Richard Hipp's software universe - You may not have heard the name D. Richard Hipp, but you've used his software: SQLite is his creation, and it's everywhere. SQLite is an impressive piece of work, but it's not alone. Along the way, Hipp also wrote LEMON, his own parser generator for parsing SQL in SQLite. And now he has his own distributed source control, Fossil, which hosts the SQLite development stream. Fossil is interesting because it's also a distributed wiki and bug tracker, kind of like Trac meets Mercurial or something. As with all of his work, the Fossil documentation is very clear about the design principles and internals, again, very impressive. SQLite's documentation includes a detailed page about how it is tested, including how its coverage is measured. Needless to say, it is well measured: 100% condition coverage! The description there of the use of C macros to enhance measurement is a good example of how macros can be extremely useful in building complex software, and makes me wish for something with similar capabilities in Python. I admire Hipp's output, but I worry that it might be somewhat insular. SQLite obviously has great acceptance, but what will happen to Fossil? It has a huge uphill climb to get users, what with Git and Mercurial slugging it out, and a dozen others competing for attention. It's the age-old dilemma about using the best technology or the most widely accepted. In this case, I don't even know if Fossil is better than the alternatives. At this point it doesn't have the critical mass that would even move it from the Curiosities category to the Look Into It list. The philosopher - Ben, my 11-year-old, has always been the artist in the family. His style has of course changed over the years, starting with stick figures, but has now progressed to more fleshed out figures. Of course, I couldn't have anticipated how fleshed-out they'd become. This is his latest, entitled, "The Philosopher": I just love watching what he comes up with... Happy 2010 - Happy 2010 everybody!
2010 looks like it will be an interesting year for me:
not to mention the usual 365 days of who knows what the future will bring. Stay happy, and take care of yourselves! SSAO JS Snowman WTF? - Román Cortés has a special place in my heart, since it was my animation of his Homer Simpson in CSS that got me my first and only Slashdotting. But Román hasn't rested on his laurels. His blog is full of edge-pushing browser experiments. So far in December alone, he's done Las Meninas in 3D with CSS, a pure JavaScript text reflection, and his latest, a 3D snowman in JavaScript. This last one, he explains, uses parallel sphere raycasting, with some simplified screen-space ambient occlusion, all built on the canvas element with direct pixel color control. Of course it does. The words describing it are practically longer than the mere 4k of JavaScript that implemented it! I don't understand what all that is (yet!), but I know Román routinely does things other people don't realize are possible. The Historical Thesaurus of the OED - The Oxford University Press is continuing to push the envelope on reference books, with the Historical Thesaurus of the Oxford English Dictionary. It's a 3952-page behemoth that not only includes every word in the OED, but traces meanings through history as well. It took 44 years to write, and weighs 14˝ pounds. It looks like pure lexicographical porn. There are some detractors, though, specifically about the classification scheme. The Amazon page has an annotated sample page, which shows that "express ill-humor" is categorized as "02.02.21.05.04.01", hardly a friendly scheme. I'm used to the Roget system, which is also numerical, but doesn't hew so slavishly to a strict hierarchy, so those same concepts can be found at 951.15, a number better fitted to my short-term memory capacity. I can imagine flipping back and forth quite a bit between index and content: "02.02.21.what?" But this still looks to be a very impressive achievement, the first and maybe last of its kind. I'll have to find a physical copy some place to further examine (peruse, study, inspect, scrutinize, check up on). BibliOdyssey - BibliOdyssey came to my attention because of tweets about their Victorian Infographics post, which is very nice, but they have lots more in a similar vein. I also liked History of Colour Systems, and especially Arabic Calligraphy: The idea that this beautiful interweaving is also writing is fascinating to me. The post has a few other examples of abstractly beautiful Arabic writing, and links elsewhere. That's what BibliOdyssey is like: a quick browse in a rich library, a brief introduction to exotic topics with pointers off to more information. There's no way to chase them all down, but I feel like in another life I could devote myself to their study... | |
| FeedSee | |