Reloadable containers for Python

We often face an issue that our long running services need some parts to be reloadable without restart of such service. To achieve this I implemented simple abstract class that wraps any container we could use. You can find whole example at my Github page. from abc import ABC, abstractmethod import time class Reloadable(ABC): """ This class wraps a container and expose all its methods. It reloads its content after `reload_every_secs` from `path`. """ def __init__(self, path, reload_every_secs=60): self._path = path self._last_update = time.time() self._reload_every_secs = reload_every_secs self._initialize_data() self.reload() def reload(self): self._last_update = time.time() try: with open(self._path) as f: self._fill_data(f) except FileNotFoundError: self._initialize_data() @abstractmethod def _initialize_data(self): """Change container to initial state""" pass @abstractmethod def _fill_data(self, fp): """Fill data from file to container self._data""" pass def access(self): if time.time() - self._last_update > self._reload_every_secs: self.reload() def __getattr__(self, item): return getattr(self._data, item) def __len__(self): self.access() return self._data.__len__() def __getitem__(self, item): self.access() return self._data.__getitem__(item) def __setitem__(self, key, value): self.access() return self._data.__setitem__(key, value) def __delitem__(self, key): self.access() return self._data.__delitem__(key) def __iter__(self): self.access() return self._data.__iter__() def __reversed__(self): self.access() return self._data.__reversed__() def __contains__(self, item): self.access() return self._data.__contains__(item) def __str__(self): self.access() return self._data.__str__() As you can see this class just wraps not specified container and whenever we want to interact with it somehow we trigger function access(). To actually use it simply implement two methods _initialize_data and _fill_data and you will have your container reloaded every few second as you can specify. ...

July 12, 2016 · 2 min

Round-robin in Celery

Recently we faced an issue how to fairly distribute computational resources for our imaging service using Celery. The imaging service does some basic operations with image like resize. We chose Celery to distribute work among our workers. The service works with chunks of 1000 images that is processed in batch. We wanted to avoid situation where one large client uses all processors on a worker and other smaller clients would have to wait. To achieve this we needed to create special queue for each client. Celery worker then takes tasks from all queues in round robin fashion. The problem is that we do not know what clients will be using our service in future and thus we needed to add queues for them dynamically. To dynamically add new queue and more consumer for it call following method: ...

July 11, 2016 · 2 min

Attending Excel@FIT

The student conference Excel@FIT held at the end of April at FIT BUT, my facutlty. I attended with an article that is based on my master thesis. My master thesis deals with effective project scheduling. I am trying to examine and improve a novel genetic algorithm GARTH.I was chosen to present my ideas in a form of a poster. You may find my article and my poster (in czech) at the conference website. ...

May 9, 2015 · 1 min

DNF to BDD in Haskell

This semester I have only two projects because it is my last semester at school (read my revaluation of study here). I am attending course called Functional and Logic Programming where we should learn this sort of programming languages. First project is written in Haskell and I chose to implement disjunctive normal form (DNF) to binary decision diagram (BDD) convertor. You can get the impression what this means from Formal Analysis and Verification lecture about BDDs on page 4 and further. As usual you can find the code at my github. It can print truth table of given formula, create ordered BDD and reduce it to ROBDD. Check the results with example formula ...

March 8, 2015 · 2 min

Overview of the study at FIT BUT

I’m trying to read some interesting articles from the field lately and I stumbled upon blog post What every computer science major should know by Matt Might, associate professor from University of Utah. He summarized requirements that proper CS graduate should comply. While reading this article I automatically started to compare his view with study programmes at my home university FIT BUT, and realized how much this school gave me in those five (at the time incomplete) years. You can check it by yourself in study programme overview (BSc. and Msc.) or read my little summary. ...

March 5, 2015 · 6 min

Pypete launch

I gladly present you my most recent piece of work in Python: Pypete - python performance tests. It is plugin to well known nosetests testing framework. If you run nosetests with my plugin turned on, it will timeit every test you have selected. You can save your results to file, compare it with older results and much more. As usual you can find my code at https://github.com/Artimi/pypete and install using pip. ...

October 3, 2014 · 2 min

Bob (Idiap) in Docker

Today I created my first Docker image. I’m really interested in Docker as a technology and I feel this should be one main route in virtualization field. The use of Docker is so easy and elegant that I wonder why it hasn’t existed for longer time. There still is big hype around Docker, especially now when they get $40M funding. With this Docker will become huge company. Anyway I wanted to create some docker image for practice and bumped into Bob, signal-processing and machine-learning toolbox that I was describing in one of my previous articles. I had a problem then with compatibilty. Bob runs only under Ubuntu, Mac OSX and Arch Linux. I am happy Fedora user and didn’t want to install Ubuntu. Luckily developers offered a solution for this situation: Virtual Machine. On the other hand it is VM in VirtualBox which is under Oracle and run demanding computation in VM with limited memory isn’t the kind of performance I was looking for. We fortunately got access to school server then, but the problem with other platforms still remains. ...

September 18, 2014 · 2 min

Sleeping Barber Implementation in Go

I wanted to learn (at least try) some new language, because I have feeling that I haven’t learnt anything in a long time. So I catched hype wave around Go. It is statically typed, with garbage collector, without OOP (I don’t like it anyway), by default statically linked language that was invented in Google. There is really nice and short tour that guided me in the beginings. Go’s killer feature is it’s concurrency model. It uses so called goroutines that are more lightweight than threads and channels that take care of communication between goroutines. ...

August 12, 2014 · 1 min

How to prepare to job interview

I had another job interview just yesterday. I do same basic mistakes everytime just because I forget how to prepare well. So I want to write this little list of things what not to forget. It will be focused on job interview to IT sector, but I think that these simple steps are applicable to every bussiness branch. Before interview Prepare answer to these questions: What did you do in your last jobs? What technologies did you use? What was your team? Why did you end your last job? What are your work plans to near future (depends on type of job internship: ~1 year, part-time: ~2 years, full-time: ~3 years)? Where you want to be in 5 years? What salary do you expect? I actually never get asked most of these questions but is better to be prepared. ...

June 26, 2014 · 2 min

Eyetracking data analysis

This should be my last project from University of Eastern Finland. In this project we was analyzing eye gazing data. We’ve got csv file containing information about positions of eye gaze in time. From that we’ve computed velocity of gaze, found peaks (high velocity, eye is moving to another object, it’s called saccades) and fixations. From that we computed Mean Fixation Duration and Mean Saccade Amplitude. I really liked to work on this project because finally I gave a try to IPython notebook and found out that it is incredible tool for data analysis and it’s presentation. You can take a look at result of my efforts. It contains all details and information. This project is hosted on github where you can find data and try it by yourself. ...

May 10, 2014 · 1 min