Skip to main content

ssh on-the-fly port forwarding

Check out this great tip from nion's blog:

ssh on-the-fly port forwarding.

I've often wanted to open up new port forwards, but haven't wanted to shut down my existing session.

If you follow this by # character (and thus type ~#) you get a list of all forwarded connections.

Using ~C you can open an internal ssh shell that enables you to add and remove local/remote port forwardings

ssh> help

Commands: -L[bind_address:]port:host:hostport Request local forward -R[bind_address:]port:host:hostport Request remote forward -KR[bind_address:]port Cancel remote forward

ssh> -L 8080:localhost:8080

100 Push Ups: Sick!

I got partway through my second attempt at week 4 again...and then started coming down with a cold which seems to have drained me of energy. Copious amounts of OJ and Cold FX have staved off the worst so far, but my running and pushup routines have suffered. I have my 10km Egg Nog Jog on Sunday, which is looking like it could be a very painful experience.

100 Push Ups: Week 4, Day 2 - FAIL!

So I didn't even come close to finishing the required sets last night.

I was supposed to do 25, 29, 25, 25, >= 36. 36! That's crazy talk!

I only managed 25 or 26 on the last set before collapsing on the floor. I think tomorrow I'll re-do Week 3, Day 3's routine, and then make another attempt at Week 4 next week.

100 Push Ups: Week 4, Day 1

I finished week 3 of the challenge without too much difficulty. Day 3 of week 3 was 22, 30, 20, 20, >= 28 and I managed 30 in the final set.

Today was much more difficult. The plan for today was: 21, 25, 21, 21, >= 32. Wow, the final two sets were rough. I'm not sure if my 32nd push up of the last set could really be called a push up, one arm wasn't cooperating, and I practically fell over trying to complete it...I'll give myself the benefit of the doubt and see how the rest of the week turns out. I have a feeling I may be repeating this week!

python reload: danger, here be dragons

At Mozilla, we use buildbot to coordinate performing builds, unit tests, performance tests, and l10n repacks across all of our build slaves.

There is a lot of activity on a project the size of Firefox, which means that the build slaves are kept pretty busy most of the time.

Unfortunately, like most software out there, our buildbot code has bugs in it. buildbot provides two ways of picking up new changes to code and configuration: 'buildbot restart' and 'buildbot reconfig'.

Restarting buildbot is the cleanest thing to do: it shuts down the existing buildbot process, and starts a new one once the original has shut down cleanly. The problem with restarting is that it interrupts any builds that are currently active.

The second option, 'reconfig', is usually a great way to pick up changes to buildbot code without interrupting existing builds. 'reconfig' is implemented by sending SIGHUP to the buildbot process, which triggers a python reload() of certain files.

This is where the problem starts.

Reloading a module basically re-initializes the module, including redefining any classes that are in the module...which is what you want, right? The whole reason you're reloading is to pick up changes to the code you have in the module!

So let's say you have a module,, with these classes:

class Foo(object): def foo(self): print ""

class Bar(Foo): def foo(self): print ""

and you're using it like this:

>>> import foo

>>> b = foo.Bar()


Looks good! Now, let's do a reload, which is what buildbot does on a 'reconfig':

>>> reload(foo)


Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/catlee/test/", line 13, in foo
TypeError: unbound method foo() must be called with Foo instance as first argument (got Bar instance instead)

Whoops! What happened? The TypeError exception is complaining that must be called with an instance of Foo as the first argument. (NB: we're calling the unbound method on the class here, not a bound method on the instance, which is why we need to pass in 'self' as the first argument. This is typical when calling your parent class)

But wait! Isn't Bar a sub-class of Foo? And why did this work before? Let's try this again, but let's watch what happens to Foo and Bar this time, using the id() function:

>>> import foo

>>> b = foo.Bar()

>>> id(foo.Bar)


>>> reload(foo)

>>> id(foo.Bar)


(The id() function returns a unique identifier for objects in python; if two objects have the same id, then they refer to the same object)

The id's are different, which means that we get a new Bar class after we reload...I guess that makes sense. Take a look at our b object, which was created before the reload:

>>> b.__class__

>>> id(b.__class__)


So b is an instance of the old Bar class, not the new one. Let's look deeper:

>>> b.__class__.__bases__


>>> id(b.__class__.__bases__[0])


>>> id(foo.Foo)


A ha! The old Bar's base class (Foo) is different than what's currently defined in the module. After we reloaded the foo module, the Foo class was redefined, which is presumably what we want. The unfortunate side effect of this is that any references by name to the class 'Foo' will pick up the new Foo class, including code in methods of subclasses. There are probably other places where this has unexpected results, but for us, this is the biggest problem.

Reloading essentially breaks class inheritance for objects whose lifetime spans the reload. Using super() in the normal way doesn't even work, since you usually refer to your instance's class by name:

class Bar(Foo):
    def foo(self):
        print ""
        super(Bar, self).foo()

If you're using new-style classes, it looks like you can get around this by looking at your class attribute:

class Bar(Foo):
    def foo(self):
        print ""
        super(self.__class__, self).foo()

Buildbot isn't using new-style we can't use super(). Another workaround I'm playing around with is to use the inspect module to get at the class hierarchy:

def get_parent(obj, n=1):
    import inspect
    return inspect.getmro(obj.__class__)[n]

class Bar(Foo):
    def foo(self):
        print ""

100 Push Ups: Week 3, Day 2...

Ok, so I fell off the wagon for a bit.

But I'm back on track now!

I did manage to do day 1 of week 3 last week...but the Real Life took over, late nights working or various other activities, and before I know it it's the next Monday and my body is screaming for rest after spending most of Sunday installing a garage door opener.

So, this is my second attempt at week 3.

I managed day 1 with little problems: required sets were 14, 18, 14, 14, >= 20, and I managed 21 on the last set.

Today was much more challenging: 20, 25, 15, 15, >= 25. I just barely managed to finish the last set. I just realized that's 100 push ups total today!