Making Functions Timeout in Python

Sometimes you need to execute a function that can take a lot of time to finish. You are not sure exactly when the function will finish, but you do not want to wait too long, or let your program “hang” waiting for a response.

We want our function to run for a certain period of time, and if this time limit is exceeded, we want to regain control of the program’s execution.

We can achieve this by using a custom context manager and the signal module from the Python standard library.

Here is a complete example:

python

Dropdown Toolbar Buttons in Netbeans Platform

It is possible to add buttons that toggle a dropdown menu to the main toolbar in your Netbeans Platform application.

For example, the Netbeans IDE Run Project, Debug Project, and Profile Project buttons have a small arrow next to them. When clicked, a dropdown menu with more related actions is shown:

Netbeans IDE Dropdown Buttons

In this article, I will teach you how to implement this behavior.

netbeans platform

Setting Up Elastic Beanstalk Health Checks With a Django Application

I was having an issue the past few days with Django and Elastic Beanstalk in a production environment that was driving me nuts.

Basically the Elastic Beanstalk environment was in a permament Severe/Degraded state. The health monitoring was reporting that 100% of the requests to the load balancer where 4xx requests:

Elastic Beanstalk 4xx requests

This issue was probably caused by several reasons. In this post I will go over the reasons I think I was experiencing it, and how it was fixed in the end.

django elasticbeanstalk

Media-Type Based Responses With Django REST Framework

Nowadays a typical REST API responds with data in JSON format. But what if you wanted to serve data in a different format (and not just a serialization format) using the same endpoint, but specified by the client?

Django REST Framework renderers can help us achieve this nice feature.

Use Case: ONIX For Books Compatible API

ONIX for books is an XML format for sharing bibliographic data pertaining to both traditional books and eBooks.

Let’s say our application serves metadata about books (title, author, etc.) in the usual JSON format, but we also want to provide data in ONIX format, which is an XML standard that defines how the metadata should be described and put together for consumption.

django

Python Functional Testing for AWS Lambda

In this post I will explain and go over how I personally write functional tests for my AWS Lambda functions.

For our example use case, we will assume that our Lambda function is quite complex, as in that it involves downloading a file, processing it, and uploading a result. Additionally it will be called by an SQS event, and it make use of other non-Python related elements, as we will see later.

Let’s get started!

python pytest aws lambda serverless tdd
Older Posts →