×


Category: WordPress


Notch Up Producer-Consumer Paradigm with Python

This article covers how producer-Consumer pattern is a very useful design which can be leveraged to a varied extent in order to enable asynchronous processing of multiple time-consuming tasks. The concept has been widely incorporated in modern-day messaging queues viz. Kafka, RabbitMQ, Cloud MQs provided by AWS, GCP, and so on.

Python provide Queue class which implements queue data structure. We can put an item inside the queue and we can get an item from the queue. By default this works in FIFO (First In First Out) manner.


The function producer will put an item inside queue and function consumer will get an item from the queue. We will use following method of queue class by instantiating queue object q = Queue().


Queue Method Python:

q.put(): To put an item inside queue.

q.get(): To get an item which is present inside queue.

q.join(): This method stops python program from exiting till it gets signal from the below method task_done. Hence this method should always be used in conjunction with method task_done

q.task_done(): This method should be called when item got outside from the queue using q.get() has been completely processed by consumer. When all items make call to their respective task_done it sends signals to q.join() that all items have been processed and program can exit.


Threads class Python:

Python allows writing multi-threaded program using Thread class. We will instantiate object of thread class and make use of following methods to process (consume) multiple items concurrently:

t = Thread(target=consumer): Instantiate thread object which would make call to function consumer.

t.start(): Starts execution of thread by making call to function consumer.


Asynchronous Programming in Python - More about this ?

This article covers how to make applications performant and efficiently use CPU cycles and threads. However, it is not all rainbows and unicorns when talking about asynchronous code.

Asynchronous programming is a type of parallel programming in which a unit of work is allowed to run separately from the primary application thread. When the work is complete, it notifies the main thread about completion or failure of the worker thread. 

There are numerous benefits to using it, such as improved application performance and enhanced responsiveness.

On the other hand, A synchronous program is executed one step at a time. Even with conditional branching, loops and function calls, you can still think about the code in terms of taking one execution step at a time. When each step is complete, the program moves on to the next one.


Examples of synchronous program:

1. Batch processing programs are often created as synchronous programs. You get some input, process it, and create some output. Steps follow one after the other until the program reaches the desired output. The program only needs to pay attention to the steps and their order.

2. Command-line programs are small, quick processes that run in a terminal. These scripts are used to create something, transform one thing into something else, generate a report, or perhaps list out some data. This can be expressed as a series of program steps that are executed sequentially until the program is done.


Install and Run Python on CentOS 8 - How to do it ?

This article covers how to install python2 and python3 on CentOS 8. By default, python2 and python3 are not installed on CentOS 8. To install both, you need to install all python packages separately according to python versions. Also, you can run python2 and python3 environments on your system. 

The 'alternatives --auto python' command is used to set any python version as the default. 


To run Python in Linux:

A widely used way to run Python code is through an interactive session. 

To start a Python interactive session, just open a command-line or terminal and then type in python, or python3 depending on your Python installation, and then hit Enter .


Python comes preinstalled on most Linux distributions, and is available as a package on all others. 

However there are certain features you might want to use that are not available on your distro's package. 

You can easily compile the latest version of Python from source.


Installing Python 3 on Linux:

1. To see which version of Python 3 you have installed, open a command prompt and run

$ python3 --version

2. If you are using Ubuntu 16.10 or newer, then you can easily install Python 3.6 with the following commands:

$ sudo apt-get update

$ sudo apt-get install python3.6

3. If you're using another version of Ubuntu (e.g. the latest LTS release) or you want to use a more current Python, we recommend using the deadsnakes PPA to install Python 3.8:

$ sudo apt-get install software-properties-common

$ sudo add-apt-repository ppa:deadsnakes/ppa

$ sudo apt-get update

$ sudo apt-get install python3.8

4. If you are using other Linux distribution, chances are you already have Python 3 pre-installed as well. If not, use your distribution's package manager. For example on Fedora, you would use dnf:

$ sudo dnf install python3


To see if pip is installed, open a command prompt and run:

$ command -v pip


Steps to install and use Python PIP tools on Ubuntu 20.04 LTS ?

This article will guide you on how to install Python PIP #tools on Ubuntu 20.04. Also, you learnt different commands which will help you in using the PIP tool. You can search, install and remove #packages by using the pip utility. Steps to Install Python #PIP Tool on #Ubuntu 20.04: 1. Update Your #APT. As always, first, update and upgrade your APT. 2. Add Universe #Repository. 3. Install PIP for Python 3. 4. Verify Installation. 5. Replace Keyword. 6. Install #Python Package. 7. Uninstall Excess Tools. 8. Additional #Commands.


Force HTTPS using .htaccess - Step by step guide ?

This article covers how to edit your .htaccess file and redirect all HTTP traffic to HTTPS which is the safe version of your website.


How to configure HTTPS for WordPress websites using .htaccess ?

1. Login into wp-admin and go to “Settings -> General”. Make sure the URL have https.

2. From the file manager, edit your .htaccess and replace the WordPress rules by the following code:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
# Rewrite HTTP to HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Note: Replace domain.com by your domain name. Make sure the position of the https Rewrite rule is same as mentioned above.


"Undefined" error in elementor - How to Fix this WordPress error ?

This article covers tips to fix "Undefined" error in elementor for WordPress users. In fact, this is the most common issues faced by Elementor users when trying to import a Custom  saved template or one of the Elementor’s default Templates.

To resolve the issue you need to click on the Sync Library button on the Template Import section.

Once you refresh the Library, try importing the templates again and it should work perfectly fine.