Close

Lazy-Loading Modules in Python

When I’m making a python package, I usually write an __init__.py which lifts the packages modules into the package namespace. Assume you have a package like this: my_package/ __init__.py module1.py module2.py module3.py If you leave the __init__.py blank, you cannot do: import my_package my_package.module1 This will result in an error that looks like: ————————————————————————— AttributeError…

Ray Tracing

Ray Tracing A Ray Tracing Adventure I’ve been entertaining the idea of writing a ray tracer for a while now and last weekend I stumbled across the excellent book “Ray Tracing in One Weekend” by Peter Shirley. I really enjoyed the read and had even more fun following along and implementing it. I dismissed Peter’s…

Python Inter-process Communication

Inter-process communication Interprocess communication in Python with shared memory The python ecosystem has rich support for interprocess communication (IPC). The multiprocessing API allows multiple python processes to coordinate by passing pickled objects back and forth. Python has full support for signal handling, socket IO, and the select API (to name just a few). In this…

Overcoming python's recursion limit.

In most programming languages, you can segfault your program by going too deep in a recursive function. In CPython (the reference implementation that you are probably using), recursion is limited to a fixed number of consecutive recursive calls. The default maximum recursion can be checked by calling sys.getrecursionlimit(). On my machine, this returns 1000 for…

LD_PRELOAD hacks

This post is a bit of a departure from my normal Python evangelism. Instead, I’m going back to my C roots and exploring the somewhat mystical world of the LD_PRELOAD environment variable. TL;DR: LD_PELOAD is a (linux) variable you can set to hijack the symbol resolution order for linked libraries. First lets consider a basic…