Is CPython Faster Without the Global Interpreter Lock(GIL)?

The Global interpreter lock(GIL) is a mechanism in CPython implementation to ensure only one thread is running at a time. This means that even if we use threads to try to speed up our programs’ runtime, this will not work because, in the end, the interpreter will block that two or more threads will be executed in parallel.

As the name suggests, the GIL is a locker that a thread gets when it starts and releases at some moment. There is only one locker, so two threads cannot get it simultaneously. As a result, our program with threads will be slower than the same program without threads because of the time to create threads and not take advantage of them. However, this is true only for CPU bound problems, which requires a large amount of CPU time to process, like inverse matrix. For I/O bound problems, CPython releases the locker as soon as an I/O call happens. We still have only one thread running at once on the CPU, but now, a thread does not block other threads while waiting for the I/O result.

[Read More]

Chrome with selenium, python and docker

Sometimes, when I execute the Chrome inside a docker container I receive the error below:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed

It is caused because Chrome uses the /dev/shm to share memory and the docker, by default, set 64MB for this partition.

Here, I will describe how to reproduce this error and how to resolve it.

How to reproduce

To reproduce this error, we need to create a docker image with chrome and python. Then, I created this Dockerfile which uses a multi-stage build to install the chrome and the python.

[Read More]

Identifying Paragraphs

I’m learning computer vision and I’m using the Opencv and Python to write algorithms in this field of computer science. This field is very interesting because it involves computer science and math and also, it is necessary to have good ideas to solve problems.

Here, I will show my first algorithm in computer vision. It is to identifies paragraphs in a text image. It consider that the image have a white background and that the characters have a black color.

[Read More]