Threading.Lock and its uses in Python

In Python you can spawn a new thread to perform a task, and then wait for that thread to finish with its task.

One of the reasons why programmers like to work with threads is that all of the threads share the same data. If you have a global variable “x”, and you start up a bunch of threads, all of those threads share the same value of “x”.  For example:

    import threading

    x = 12345
    y = 'hello'
    z = [10, 20, 30]

    class MyClass(threading.Thread):

    def run(self):
        tid = threading.get_ident()
        print("Thread {0} has x = {1}, y = {2}, z = {3}".format(tid, x,y,z))

    for i in range(5):
    t = MyClass()
    t.start()

In the above code, we create five instances of MyClass, each of which has a “run” method. We invoke that “run” method within a new thread with t.start(). Within each thread, we have access to all of our global data.

This might lead you to believe that you can modify data from within the threads. And that would be a very, very bad idea. This is because Python’s built-in data structures aren’t “thread safe.”  This means that certain operations require several low-level instructions, and that Python might start executing a different thread partway through those instructions. If A and B are both modifying the same data structure, then we’re in trouble.

Note: All text before this line is just a snippet of the article Threading.Lock and its uses in Python, published in the newsletter Better Developers. The author of the already mentioned article is Reuven M. Lerner. Subscribe today to Better Developers using this link.

Workaround for tracker-miner-f high CPU utilization

High CPU utilization
Workaround for tracker causing high CPU utilization

One fine day I heard a laptop of mine making a sustained noise. I thought immediately of high CPU utilization. My intuition was right.

The issue was happening in Debian 11, running the Linux kernel 5.10.0-17-686-pae. Yeah, you’re right, it’s an i686 still functional machine. The issue began suddenly, but once it started remained happening for hours with no signs to stop.

I checked the processes using “top” and soon found the culprits. They were:

  • tracker-miner-f
  • tracker-extract
  • tracker-store

I have never seen these guys before, so, I started browsing the web for advisory… I found a good match in the thread tracker-miner-f taking over 100% of cpu. First, I learned that tracker-miner-f is Gnome’s file indexer. I had no idea about it. Anyway, I searched for any systemctl command to disable it, and found none. OK… so, I continued reading and figured out to uninstall these packages:

  • tracker-miner-fs
  • tracker-extract
  • tracker

but I noticed a removal of any of them (or all of them) would impact nautilus; so, I dismissed the idea of uninstalling them.

Then, I emptied the cache of tracker:

rm -f .cache/tracker/*

but the issue came back later.

Read more

VNC server installation on Linux Mint running the Mate desktop environment

VNC server on Linux Mint Mate desktop

Introduction

The installation of a VNC server on Linux Mint -running the Mate desktop environment- can be accomplished by following this step-by-step guide. The procedure below is scoped to run the vnc server on demand, it is, only when required.

Procedure

First thing anyone should do is to trigger an update of the packages from the corresponding repositories. To accomplish this, simply run:

sudo apt-get update

I would say it should be good to upgrade the versionof the installed packages by running:

Read more

NFS 4.1 support on Azure File Shares

NFS

The NFS 4.1 support on Azure File Shares -in public preview- is a fully POSIX-compliant offer ideal for workloads that require POSIX-compliant file shares, case sensitivity, or UNIX style permissions (UID/GID).

The NFS 4.1 support -in preview– on Azure File Shares is available in a number of Azure regions. You may find additional information about NFS 4.1 support on Azure File Shares in these articles “How to create an NFS share” and “Azure file share protocols“.

Installation of kubernetes on Azure virtual machines

kubernetes installation guide

This is a demo guide of how to install kubernetes master and worker nodes on Microsoft Azure standalone virtual machines.

This guide is not intended as a solution for production purposes.

Pre-requisites

This guide assumes that you have a Microsoft Azure account and that you installed the Azure CLI and you are logged in to the respective subscription in Azure.

First steps

To create a resource group:

az group create -n rg_k8sdemo --location eastus2 --tags Purpose=Education

To create a VNET:

az network vnet create \
--resource-group rg_k8sdemo \
--name vnet-k8s-101519 \
--address-prefix 10.0.0.0/16 \
--subnet-name subnet-k8s-101519 \
--subnet-prefix 10.0.0.0/24

To create a virtual machine (as master):

az vm create \
--location eastus2 \
--size Standard_B1ms \
--resource-group rg_k8sdemo \
--image UbuntuLTS \
--computer-name my-k8s-master-00 \
--name k8s-101519-master-00 \
--vnet-name vnet-k8s-101519 \
--subnet subnet-k8s-101519 \
--storage-sku Standard_LRS \
--ssh-key-values .ssh/id_rsa.pub \
--tags role=master

Read more