logpad

keeping logs, etc.

The Twisted Reactor: Part 1

Note: I take a lot of what’s written here from these papers – be warned though, not everything written there would still be valid, they’re over a decade old. I’d also suggest you read Glyph’s The Twisted Way (he speaks Zen) or the krondo tutorial or Jessica’s book.

A couple of assumptions I make about you – that you are familiar with basic socket programming, and know a little bit about I/O multiplexing (select etc.)

In this first post, we’d see what a reactor is, and how it works. In the second part, we’ll talk about how you should and should not use it. The third part will talk about what’s wrong with the way Twisted’s reactor works now, and how it should be instead.

I wish I was only doing an imitation of a dumb user rather than really being one.

My first interaction with the reactor was when I was writing tests for an endpoint. I’d only heard about The Reactor – no one ever talked about how it worked, but everyone knew that it worked. And that it worked pretty well. To understand what a reactor was really doing, and what all the fuss was about, I looked for it hoping to unveil some magic. Alas, not much was found there; it again led to me looking through other some places, which, again, had little besides docstrings in a skeleton.

Since I did not find much in the twisted.internet.reactor module, I looked at the next best alternative, the MemoryReactor, which is a test double that one could use to test code that uses a reactor (e.g. TCP connection attempts). If you’ve been paying attention so far, you’d know that my goal was to test an endpoint. And a fake reactor was sufficiently serving my purpose. Also, MemoryReactor had enough code to tell me what it does when an endpoint is used to establish a connection. Case closed. Until one day, when I had to write tests for another endpoint, which required me to write my own fake reactor. One thing led to another and I ended up understanding the Twisted reactor architecture. And here’s an attempt to help you understand it too.

PyCon 2013: Down the Rabbit Hole

So there was PyCon. And there was me.

Now there are two ways in which I can tell you how it was. I can use some really big words and give you a dry report of events. But that’s boring, and there’s enough boring stuff out there.

“Speak English!” said the Eaglet. “I don’t know the meaning of half those long words, and I don’t believe you do either!”

So here’s a recollection of whatever I can remember, without using many big words.

Twisted Logic: Metaphorically Speaking

Note: This is the first post in what I hope will be a series leading to my talk at PyCon US, 2013.

Up until the late 1890s, atoms were thought to be the smallest possible division of matter. And then someone discovered electrons. It was easy to relate this new model of atom to the British dessert, plum pudding - negatively charged “plums” surrounded by positively charged “pudding”(though, in Thomsom’s model, electrons were not stationary, but that’s another story).

Now things seemed to be going fine, till someone else gave a new theory. And we all corrected ourselves: atom doesn’t resemble the plum pudding, instead it resembles a planetary model, with a cloud of electrons surrounding a nucleus of positive charge. Alright.

The Thing That Runs Your Python

(This post is mostly based on a discussion that took place on IRC, when I investigated what PyPy is, with excellent inputs from glyph and fijal)

Implementations

Before we get to PyPy, we need to understand what the implementation of a language means.
A program that interprets the programs you write is called an implementation (of that programming language). For example, gcc and icc are different implementations of C (and clang), while CPython and PyPy are implementations of Python.

Build Something, Maybe?

It’s been a few weeks since my internship with Twisted came to an end, and did I mention I just released Twisted 12.2.0?

Myth of the Genius Programmer: Revisited

My 9th grade English teacher had once lectured us for over 30 minutes on why we should neatly strike out any errors, spelling or otherwise, we make in the exams, and not smudge it away and try to make the mistake indecipherable to the teacher. “We really don’t care what the error was, as long as it’s struck off, we probably won’t even read it. So, please don’t dirty the answer-book, it hurts our eyes.”, she’d said with a deep sigh.