2. Until now you never could have such a deep insight in how your app allocates memory. The tool is a must for any long-running services implemented with Python. With memray you can generate flame charts or all allocations and trace absolutely everything.
3. And this must be a Python snippet of the month:
4. It's sophisticated enough to peek into native code. So you can profile your numpy and pandas code with it. And it has a live mode. You can just run your code and see how it allocates memory as it runs. 🤯
5. A little birdie mentioned to me that @pyblogsal is one of the active contributors in memray. Let's keep it a secret 🫢
Let's talk about Python metaclasses. 🎩✨ Many think they are magical things that mere mortals should never use. That's not quite true, although in many cases metaclasses can needlessly complicate things. Beware.
Read the thread! 👇👇👇
Note: the purpose of this thread is to show how to use metaclasses via a few examples. There are a few simplifications here and there for the sake of brevity. If you want to understand how things work I suggest to start with the official documentation: docs.python.org/3/reference/da…
1. We first need to talk about regular classes, and specifically about __new__() and __init__() methods. The former is actually a static method—it's called when an instance of the class is constructed. The __init__() method then initializes that instance.
Let's talk about immutability. Python, unlike languages like Clojure, Erlang, and Rust is built entirely around mutable state. I'm going to try to convince you that immutability is awesome and can be effectively used in Python today.
Thread 👇
1. If an object is immutable it means that its state cannot be changed after it is created. For instance, in Python you can't change a character in a string, or reassign an element of a tuple. Python ships with a few immutable datatypes: str, bytes, tuple/namedtuple, frozenset.
2. Users can of course create their own immutable datatypes / objects. If an object doesn't have API to mutate its state and all of its public attrubutes are exposed via a readonly @property it is effectively immutable.