Take apart. Make science.

welcome

  • My job search in 2021-2022

    Gathered some stats about my recent job search.

    Continue reading →
  • Sole underscore in python

    A sole underscore _ is often used in code snippets to drop one or more outputs.

    proc = subprocess.Popen(...)
    _, errs = proc.communicate()
    # do smth with errs
    

    Why do we use _ in place of a variable name in this case? Is it a convention or there is some magic behind? Let’s investigate with dis.

    Continue reading →
  • pyteleport - teleporting python runtime

    cut_image

    I often find myself in a situation where different parts of a script are most optimal to run in different environments. Like, for example fetching the configuration can be done locally, dataset manipulation is best done in a many-CPU environment, while machine learning requires a GPU-capable machine. Managing this is a nightmare: you split jobs into multiple steps, save intermediate results, deposit and transmit data, schedule job chains, and, most annoying, ensure the integrity of the whole run. There are many infrastructure solutions for this problem which come at a price of having to deploy and to maintain them as well.

    Instead, I was recently inspired by the idea of forking a process to another machine right in the middle of its execution. Indeed, it is rather tempting to not worry about intermediate variables which you have to save and to load, often from cumbersome locations, and to just swap the environment without interrupting the logic. I created a tiny proof of concept which does this in the context of python scripts. Also available on pip: pip install pyteleport. This post is about technical details of pyteleport and transmitting runtime states in general.

    Continue reading →
  • Random discoveries 1

    A collection of small hacks which I discovered recently. This time: ssh ControlMaster and the synergy of dataclass and @cached_property in python.

    cut_image

    Continue reading →
  • Micropython

    cut_image

    Python is the language that I write most of my code in and cPython is the interpreter that I use. That’s quite typical: python is cPython 99% of the time. But what is that small fraction of other python interpreters? Today I am featuring micropython: an independent project that fits python language into tiny (few kB or MB) bare metal platforms.

    Continue reading →
  • 'di' - the reverse of 'id' in python

    id(obj) returns an integer with object address in python (cPython). What about the reverse: return python object by address?

    Continue reading →
  • Hacking python bytecode in runtime: custom 'return(...)'

    Python flow is controlled by a number of statements, such as for, if, while, raise, try, return. These are a part of python language which you are not allowed to (re-)implement by yourself. Or are you?

    Continue reading →
  • Modifying immutable objects in python

    In python, strings and bytes are immutable objects which you cannot modify. But what to do if you absolutely want to? The nastiest way to do it is to overwrite the corresponding memory block. Here is how you do it in pure python.

    Continue reading →