Image for post
Image for post

This article is dedicated to explaining, reproducing and resolving the “Fatal Python Error: deallocating None” which can happen while using the PyGreSQL package to query PostgreSQL data. This error only occurs with very specific queries and when either querying large amounts of data or querying many times without restarting the script or server.

I’ve reported this bug on github and it should be resolved in PyGreSQL version 5.2.2 but in the meantime I will present two workarounds without the need to upgrade.

Understanding the error

In order to understand and resolve this error we first need to know a little bit about Python’s memory management. …


Image for post
Image for post
Photo by Hitesh Choudhary on Unsplash

I have been coding in Python for over a year now and I’m always on the lookout for writing more Pythonic code. I wanted to share some useful functions and libraries I have learnt about and started using regularly to write concise and hopefully Pythonic code. I have tried to keep the article brief but provided extra links with more information.

Preliminaries

You can find useful style guidelines and conventions like naming conventions at https://www.python.org/dev/peps/pep-0008/ but in this article I want to focus on writing cleaner and faster code.

The most iconic way of writing more Pythonic code is probably using list or dictionary comprehensions instead of a for loop. For instance, let’s say we want to make a list of the first five multiples of 2. …


I recently had to write some Python unit tests for functions that use Redis and PostgreSQL databases to store data. To achieve this I had to learn how to use Pytest and packages which would be able to fake a database connection. The latter proved particularly challenging due to the lack of good documentation and useful examples online. I spent a lot of time googling and figuring out how to make these fake connections in tests and setting up a test framework. As a result I wanted to share what I did to help anyone else looking to write similar tests save time. I’ll first do an example of a fake Redis connection and then I’ll look at a fake PostgreSQL connection example. I’ll assume some knowledge of Pytest (I got started with this useful article https://medium.com/testcult/intro-to-test-framework-pytest-5b1ce4d011ae) and Redis/PostgreSQL databases. …

About

Szymon palucha

Software Engineer at Luminance Technologies Ltd

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store