Werkzeug & Reloading

I got tired of Werkzeug's runserver being so slow to reload (it polls once every second) combined with VMware's "shared folder" thing being so slow to refresh. It sometimes took up to 3-4 seconds to reload. Clearly not doable for a guy with over nine thousand words per minute!!1

So, like any responsible sendapatch.se member, I decided to take matters into my own hands and send a patch.

First, I modified Werkzeug's serving.py so it listens to SIGHUP for reloading itself.

Then, I run this line in a shell on my Mac OS X:

while until_changed **/*.py **/*.html **/*.jst 2>/dev/null; do
  python - <<PY
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto("PING\n", ("VMWARE_IMAGE", 12345))
s.close()
PY
  date
done

until_changed is a utility I wrote that uses Apple's FSEvents APIs from Python. It exits as soon as any of the given arguments is changed.

Then, on my VMware Linux image, I run this:

socat udp-recv:12345 stdout | \
(while read; do
     pkill -HUP -f 'dev.py runserver'
 done)

That made it reload very quickly. In fact so quickly that the filesystem on the Linux guest OS didn't have time to refresh before Werkzeug loaded the code again, so it started reloading twice. And still just as slow. Once for my immediate hook, once for detected filesystem changes.

So that was clearly untenable. A non-solution if you will. Scratch the SIGHUP stuff. (I still have the changes if anybody is interested.)

Without NFS, rsync or something to that extent, would have been an exercise in pointlessness. But fear not. Setting up the OS X side to do rsync is so trivial! See:

rsync -ave ssh ./ rsync://lericson@VMWARE_IMAGE:devel/src/

Slap this into a similar while loop to the ones above, and you've got yourself a simple and effective synchronized directory. (The reason I chose to use rsync's own protocol is that it has very little initial negotiation -> schnappiness.)

Next up: Werkzeug's runserver needs pyinotify support, to reload near-instantaneously as the rsync completes.

Update So I made inotify support for Werkzeug, and Ronacher is going to merge it any minute now. Totally awesome.


Apple Bullshit: iPhone text input

I'm an Apple user. I have a MacBook Pro, and an iPhone. I get the whole "Apple sucks" thing about every day (mostly from Android/Linux users, hm).

But honestly, Apple? Why can't my iPhone learn new words? Why is that not a possibility? My first cellphone could be taught new words. It adapted to my vocabulary over time.

The iPhone pretends to. It stops making some corrections. For example, writing "åå" used to correct to "på" ("on"), but because I actually used that correction a lot (convenient to type the same character twice), the iPhone then stopped correcting me on that. Huh.

Let me briefly introduce you to the letter Ä. It sounds just like E in many cases, and the glyph comes from an A with a lowercase "e" above it. In Norway it is known as Æ. In Swedish, if you end a word with Ä, it isn't uncommon to add an E to the end. Like the word for "no", "nej", is usually written "nä", but since that's so short, a lot of people (myself included) write "näe". What does the iPhone do? Corrects it to "när". Means "when". Thanks.

The worst part about it all is the interface workflow Apple chose. They must've thought their algorithm is never wrong. Why the f*** else would you make corrections to my text when I hit "Send"? Ridiculous.

And why am I not allowed to add to my dashboard an item that disables 3G or cellular data altogether? Because Apple engineers failed to conceive of the need? Why the hell does the functionality of a piece of electronics in my hand depend on people I don't know in f***ing America? Ridiculous.

Because that's another thing: toggling settings on the iPhone is awkward at best. You have to go into the Settings application, navigate your way through sections upon sections of settings, and then toggle your favorite setting. For example, I as I said disable 3G (because my battery holds 3-4 days with it off, and less than 24 hours with it on) - how?

Why simple, just push Home once. You push twice, sorry, try again. Then, find the Settings app, you're going to have to have it on your first page anyway so you might as well move it already. Navigate into the "General" subcategory. Find the "Network" subcategory and tap on it, it's a little bit down. Find "Cellular Data" and toggle the switch.

Frustrating as hell is what it is. People constantly congratulate themselves for using Apple, saying "here somebody thought about the UI." Bull f***ing shit, they sat in focus groups and alleviated the common usecases for the phone. A phone that does not allow power users to wield it fully.

Speaking of bullshit UI from Apple, iTunes, more precisely iTunes export feature. iTunes is often hallowed as the crown jewel of amazing UI. I think more like crown turd of craptastic UI, but I digress.

iTunes has this concept of your organizing your music into a library. Right. You drag stuff into a library, files or whatever. If you lose your harddrive, sorry that's your library with it -- syncing your iPhone won't help, because the new iTunes install will actually clean out your iPhone. Thanks.

Anyway, you export things from a library, you expect them to be exported, right? Not duplicated. Guess what happens when you export stuff in iTunes? You get the export progress UI, then when the export is done, bam. Gone. The files you exported are now in your library, looking exactly like the files you exported from, so you don't know which is which.

Wait what. Why... What. Why the f*** would I want to do that? Makes no sense at all. I have an album. I'm creating a zip of an album so my mate can listen to it (this is legal, like passing on a CD).

iTunes helps me in the following way: the music I bought on iTunes Music Store is labelled with my e-mail. What is up with that, Stasi Apple? Secondly, it'll let me "Create AAC version" (or whatever my exporting options are set to). This then results in the album being duplicated in my iTunes folder, with no simple way of determining which of the two items is the latter duplicate.

In general though, OS X is great. The fact that you can query almost any service from a shell really matters. But when it comes to iOS and embedded devices in general, Apple is a whole other story. Apple will never let you browse or edit the filesystem of an iPhone. Ever.

Let that sink in for a moment.


RSS 2.0