Abusing Python frame and code objects
Suppose that you want to find the value of the first argument to thefunction that called your caller . While the inspect module documents the types involved, it doesn't really explain what the membersare; here's what I've worked out.
Start with a frame, for example from calling inspect.currentframe() to get your own frame and then backing up a couple of frames to yourcaller's caller via f_back . The values of all of the function'slocal variables are
Attribute tracing as a mixin class
Attribute tracing as a standalone class haslimits if you want to trace access to all objects of a particular class,not just a few of them; you wind up having to hunt down all the placeswhere you manufacture new instances and modify them and so on. So let'stry an attribute tracer as a mixin:
def _getname(obj): cl = obj.__class__ return "<%s.%s>" % \ (cl.__module__,
A thought on trackbacks
One corollary to different views on what comments are for that has struck me is different views on how desirableand useful trackbacks are.
To wit: if you feel that comments are a conversation, trackbacks arean annoying distraction; they are an attempt to pull people away fromthe conversation to another site (or page). However, if comments area collection of reactions, trackbacks are clearly desirable; theyaggregate the reactions on other sites into one place.
My personal view is that I am most interested in comments as
BitTorrent trackers are not innocent bystanders
Every so often, I see someone put forth the view that BitTorrenttrackers aren't at all responsible for what they help distribute becausethey operate without actually knowing anything about the torrents theycoordinate. In practice this is wrong.
People say this because in theory a tracker (or at least an unencrypted one ) doesn't have to knowanything more about torrents than their SHA1 hashes, or more technicallysome shared key of the right size that all the clients agree on; to thetracker it is an opaque
A brief mention of some tools for debugging Linux NFS client issues
Someone here recently asked for tips on debugging a mysterious LinuxNFS client hang. I didn't have any answers, but I did happen to knowwhere to look for some Linux-specific tools. (The person had alreadyexhausted the abilities of things like tcpdump to help.)
The most obvious thing is to use the magic SysRq to get a dump of the kernel call stacks of all processes (the t command). Once you find the hanging processes in all of the output, youcan usually see what
What Linux's RPC queue dump means, sort of
Since I went digging through the kernel source code yesterday , here is the meaning of the fieldsin the RPC queue dump that you get any time you write to /proc/sys/sunrpc/rpc_debug .
As far as I've been able to work out, the useful fields are:
-pid- | An internal RPC sequence number; it has nothing todo with process PIDs, despite the name. |
proc | The RPC procedure number being invoked, in decimal;you can find which NFS action is which |
The irritation of single-context applications
One of the extra irritations of many single instance applications is that they also are what I will call'single context applications', applications where you can only bedoing one thing at a time. I want applications like my feed reader or my mail reader to behave more like abrowser, letting me rip off windows so that I can skip around withouthaving to lose the old context.
For example, consider a mail reader. If I'm working my way throughsorting and cross-checking older mail and new
Dear ZFS: please stop having your commands stall
One of my serious irritations with ZFS is how various ZFS commands (orat least sub-commands of zpool ) will stall badly if it can't talk tosome of the underlying disk devices. This is especially apparent whenyou're using iSCSI; for example, I accidentally booted a system with theiSCSI cable plugged into the wrong port, and once the system had booted zpool list simply hung.
(Worse, it hung uninterruptibly; I could not stop it with ^C, use jobcontrol to background
Finding the name of your caller in Python
One of the things that would be useful in an access tracer is reporting not just what was accessed, butwhere it was accessed from. A basic starter for this is knowing whatfunction called you.
CPython has enough introspection faculties to give youthis information, but it's not entirely documented how todig it out. The big tool for this is the inspect module , and wecan use it to define a function:
import inspect
def getcallerinfo(): fr = inspect.currentframe() try: fr
What FAQs are
Here's a question: which type of documentation is the ever-popular FAQ format?
My answer is that in practice, FAQs are a collection of tutorials; theytell you how to do various specific frequently asked operations. Thishas important implications if your primary documentation format is FAQs,because FAQs effectively have drawbacks from both sides; they're notas well organized or as comprehensive as reference documents, and theydon't give you an overall view the way a single unified tutorial does.
(That they