Tracing python programs. Today, Evan Dandrea asked a general question “Where is set -x for python”. A quick google for sys.settrace found: Some code snippets. I thought this was nice, but surely you want to be able to just trace an arbitrary program. So I present a ‘quick hack’ (5 minutes precisely :)) to do that based on the previous links final version:
import linecache import os import os.path import sys
def traceit(frame, event, arg): if event == "line": lineno = frame.f_lineno filename = frame.f_globals["__file__"] if (filename.endswith(".pyc") or filename.endswith(".pyo")): filename = filename[:-1] name = frame.f_globals["__name__"] line = linecache.getline(filename, lineno) print "%s:%s: %s" % (name, lineno, line.rstrip()) return traceit
def main(): search_path = os.environ.get('PATH', '').split(os.path.pathsep) argv = sys.argv[1:] if not argv: raise Exception("No command to trace supplied") args = argv[1:] command = argv if os.path.sep not in command: for path in search_path: if os.path.exists(os.path.join(path, command)): command = os.path.join(path, command) break del sys.argv source = open(command, 'rt') exec_symbols = dict(globals()) exec_symbols['__name__'] = '__main__' sys.settrace(traceit) exec source in exec_symbols, exec_symbols
I send mail from my laptop by a local smarthost-with-auth install of exim4. Recently I got motivated to setup smtp submission port for this, as I got tired of borked hotel wifi intercepting smtp, and was behind a firewall that allowed no smtp out…
It was pretty simple – on my mail server, enable listening on port 587 by putting: ‘daemon_smtp_ports = smtp : 587’ in before the local_interfaces line.
And on my laptop, edit the ‘remote_smtp_smarthost’ stanza to add ‘port = 587’.
Yay to less mail headaches.
thank you lazyweb; A number of folk have written to me pointing out Netem. One in particular, Yusuf Goolamabbas even provided a set of wrapper scripts for Netem that I’m going to be digging into next week.
Netem is built around various lower level tools like tc, which is good (tc is what I was using year ago). I’m hopeful it will be really easy to use, and will blog something when I’ve used it in anger :)
In bzr development we are now working primarily on network performance. One of the key things about being sure we have improved things is automated, repeatable benchmarks. And for that to be useful in networking environments we need to control latency and bandwidth and packet loss.
I know this isn’t a new problem, but it was about 5 years ago that I last did this sort of thing. What are the best tools today (for linux :)). Ideally I’d be able to bring up a bunch of local addresses like 127.0.1.1 or 127.0.0.2, with different properties – such that traffic from 127.0.0.1 to 127.0.0.2 will simulate being uploaded over adsl, and 127.0.0.2 to 127.0.0.1 will simulate being downloaded over adsl.