Monthly Archives: August 2008

Debugging in Python

A quick reference on how to debug Python applications (this is of course specific to shell environment, no IDEs involved).

Python features a debugging module called, unsurprisingly, pdb (Python DeBugger).
To activate the debugger add this at the beginning of your program:

import pdb

You can then set one or more break points by placing the following text:

pdb.set_trace()

Start the program as usual, once the break point is reached the interpreter will stop and wait for your input, you can then enter:

  • “n” to execute the next statement
  • “q” to quit
  • “p ” to print the value of one or more variables (use comma to separate)
  • “c” to stop debugging and continue with normal execution
  • “l” to see where you are in the code, if repeated it will show more lines
  • “s” to step into subroutines
  • “r” to continue (stop debugging) until the end of the current subroutine

Please note that:

  • You can just press the ‘enter’ key to repeat the last command
  • You can change a variable’s value on the fly by adding a leading exclamation mark to the standard Python syntax, it tells pdb we’re entering a statement instead of a command (e.g. !text = “hello”)

Happy debugging.

Fail to mount root filesystem after dist-upgrade

Some days ago i performed a dist-upgrade command on a Debian Etch server with two disks RAID1+LVM and it ended up with a new 2.6.25 factory kernel.

After a reboot it was stuck in BusyBox unable to mount the root filesystem…

I then rebooted and selected the previous kernel, same story (failsafe kernels as well)…

I realized (thanks Linux for being so verbose) there was a problem in creating the /dev/mapper directory and therefore no chance to be able to mount my raid.

A deeper inspection revealed that the mdadm script in BusyBox to mount the raid used the command “mkdir –parent” but long arguments have been deprecated in recent versions of BusyBox. Even worse: the correct syntax would be “–parents” (they even lost the trailing “s”), shame on you Debian mantainers.

I therefore had to manually extract my initrd (which is a gzipped cpio archive), edit the mdadm script and recreate the initrd with mkinitramfs.

It worked but i’m quite disappointed i haven’t found yet an “official” clean solution about it.

CentOS 2 – 0 Debian