Brandon's Blog

6/13/2006

Python, and the Threat of Mutexes

I have musing time, we might say.  Much time for musing.

I muse about Postfix (a lot), but Postfix – in terms of my limits of musing – is not much more complex than the knowledge I have succeeded in unearthing so far.  The puzzle of mailserver configuration is receding, as I have untangled the “mess” I encountered in ignorance.  What was beneath was yet another mess, but a predictable mess, which does not require musing to comprehend.

Once aware of the limits, there is not much more to learn.  A paraphrased engineer’s mantra: “At this point, I understand what concepts I need to know, and I can look up anything else in a book.”

So, what do I when mailservers do not bear fruit?  Correct!  I muse about Python.

Talk about a mess.

I looked into multithreaded Python.  I know I will divulge why in but a number of lines, but I dread that.

I think I am internalizing something I have never before understood about those dreaded locks, those mutexes: they lock code, not data.  (I think.)  I guess it’s because I’m a very unqualified database nut, that I would focus on the data.

Then I saw this article, which explained that Python isn’t thread safe and you have to call the sleep() function just to get the system to switch over and execute other threads.  There needs to be an expression combining “Umph” and “Yuck.”

Okay.  Time to fess up.  Deja vu now, but it dawned on me (or maybe re-dawned on me) how easy it would be to port Sigma (or some significantly diminished skeleton of it, for starters) to Python.

My nasty select() UNIX sockets code would become a portable object implementation of the TCPServer class, which would mean I would have a 5-line socket server running in about 10 minutes.

I estimate that approximately 20-30% (non-comment LOC) of my class implementation for Object-derivatives (Object, Character, Denizen, Player, Room, Item, I believe, or check the docs) is devoted to libxml2 parsing.  “Umph” . “Yuck” again (ha ha, used the period to concatenate a la PHP).

Python, of course, has an XML DOM for this.

Another maybe 10% of my overall C++ program is implementing Mickey Mouse list classes that emulate queues, etc.  Of course all that is neatly supported.  I don’t even want to talk about string parsing.

When I think about all the work that went into my little library functions, it “puts a tear in my beer” as a work-friend from last year would say.

Well, better get off this one before I add another page or two.  I’m sure there will be more later.