So there you are, with a class that has over 100 (200? 500? 1000?) lines of code in Python. Wow, such an impressive achievement. Life with a monster like this can’t be easy. History of our giant class is irrelevant. What’s important is that our patient is sick and needs a treatment. We’ll cure it, […]
Category: python
asyncio – choosing the right executor
During application development with asyncio you will inevitably encounter situation when there is no asyncio-compatible library to use. It may be an API client for our business partner built with excellent requests library (that naturally doesn’t work well with asyncio) or a simpler example – a Celery. Rewriting problematic dependency may be your first thought, […]
Writing custom checkers for Pylint
In the world of Python we have quite decent tools for a static code analysis. There are pylint, flake8, pep8 just to name a few. Rules they enforce are based on a solid foundation – PEP8 – Style Guide for Python Code. Beside style & convention related issues, tools for SCA can detect errors like using […]
Django – squashing migrations versus continuous delivery
Every Django project may encounter a steady increase in a number of migrations over time. One way to lower their quantity is to use squashing. Squashing amounts to taking contents of few migrations and connecting them into one. This would reduce their number, but what happens if we squash a bunch of migrations that were […]
Dive into Python’s asyncio, part 2
All examples were tested under Python 3.6. The only asyncio rule After reading part 1 you should already know, that a heart of asyncio is an event loop. There is exactly one rule – do not block the event loop! Never ever. Fortunately, it’s quite simple to avoid this. Use only co-operative libraries for blocking […]
Dive into Python’s asyncio, part 1
Concurrency was not seriously taken into account in Python when it was designed. Until 3.4 version, there were two options: threading multiprocessing Although these two modules provided programmers with handy primitives and API, they both have considerable downsides. Due to GIL presence, threaded code in Python never actually run in parallel. So all attempts to […]
Collections in Python’s standard library: dict
Warning: this post’s contents is based on Python 3.6rc1 source code – most recent available one at the moment of writing. Dicts are omnipresent A lot of things in Python are dicts. Your programs use dictionaries extensively even if you do not explicitly instantiate them. There is a global registry of loaded modules, so they do […]
Python 3.6 new features – formatted string literals
On 23. December 2016 new minor version of Python was released – 3.6. It brings few enhancements and syntax features. In my opinion the most notable one is introduction of formatted string literals. word = ‘world’ print(f’Hello, {word}!’) # prints ‘Hello, world I always envied Ruby’s string interpolation because it is much cleaner and doesn’t […]
What is celery beat and how to use it?
Celery is a widely recognized distributed task queue for pythonic projects. Its sole purpose is to reduce load of web servers by delegating time-consuming tasks to separate processes. Our web servers should handle one request for no longer than a fraction of second, therefore running long tasks synchronously substantially reduces application’s throughput. So we are […]