Category Archives: Python

it seems Eventbrite has some pro Django peeps

Tonight I went to this Pycon practice talk at Eventbrite, and it was really great!   Simon Willison, who helped create Django at the Lawrence Journal-World gave a talk about feature flags and talked a bout things like flags for “maintenance mode” for a site, which is useful for having to make a site read-only.  One particularly interesting thing he noted about this was how you could create a custom auth middleware which basically ignored the user cookie.  And so, since this would make users not be able to login and modify data, your site could make progress towards being read only.   He also explicitly mentioned that the notion of “read only”-ness wasn’t at the SQL level, as you might think.  Instead, the preferred method was just to disable all possible ways of doing stuff!

Andrew Godwin, who I didn’t catch as “famous” at first but eventually realized as the creator of South gave a talk about API services and Eventbrite, and Lanyard’s migration from MySQL to Postgresql.

One cool thing I wrote down was this UserBasedExceptionMiddleware which could be used to show the debug page to a superuser even on production!

from django.views.debug import technical_500_response
import sys

class UserBasedExceptionMiddleware(object):
    def process_exception(self, request, exception):
        if request.user.is_superuser:
            return technical_500_response(request, *sys.exc_info())

ctrl+c dosen’t cancel a running Python script that uses threads?! /gasp

welp, ctrl+c is my best friend when it comes to bailing out of a program where I screwed up or is taking too long for my gamer-esque patience

It turns out you actually gotta kill -9 the process!

The answer to “why” this is the case is around 22:00 to 25:00 in this  presentation, “Inside the Python GIL”  by David Beazley:

This came about as recently I’ve been working on a Rackspace Cloud Files container replication program, and I’ve been working on trying to speed it up in ways so that it completes in a “reasonable” amount of time.   

I first gave it a shot at it with the multiprocessing module.  Soon enough though I found I couldn’t use it due to the inability to pickle an SSLObject.  Which, I guess the cloudfiles.connection.Connection I was using to connect to the Cloud Files container was using.

At this point I went searching for an answer, and tangentially discovered that Cloud Files’ origin was actually from a separate company named Mosso, which Rackspace acquired and turned into their cloud service thingy!

My second try was more successful:  using the threading and Queue modules to create a specified number of worker threads to run replicate() method over a queue of container objects.

And this is where I discovered this ctrl+c weirdness/intricacy.  I’d have a bug or some stack happening which I could see from the debug output.  Wanting to exit out early, I’d bang on ctrl+c to absolutely no avail!  Sooooo weird!  haha