Skip to main content

Things you should know about Python as a Developer

Hey readers, today I am going to write something interesting about Python that every developer should learn about.

This is about the Python Programming Language, it's speciality and some pitfalls. So let's begin start exploring and learning about this beautiful high-level programming language.

Python is an interpreter based language. To elaborate, when we write the code in python, every section of the program gets compiled not like that of Java, C++ and C where the entire program is compiled first and we run the compiled file to get the output. Here in Python, it is different so the variable(let's suppose x) is an integer at line number 4, the same variable can be the list at line number 5. So, it is called dynamic language.

Another important thing about Python is it has a Global Interpreter Lock (GIL) which prevent two thread to run parallelly simultaneously. That means when there are multiple threads in Python they use the 'coordinated multi tasking' feature to run the thread at the kernel level. 

I have a very good example to describe this feature.

When you run two threads with help of the python programming language in an octa-core computer. Those multiple threads can only take 100% of one single core of that computer, whereas in other languages like C++ you could take 100% of eight different cores to run the threads. So here in this example, two threads in python language could only share 100% with each other (for eg: 50% each) while the other core is not used although they may be free.

We can use threading in python by importing Thread from threading and use threading by using the following commands :



So to achieve multiple running of two tasks we can use multiprocessing only. The procedure is similar to the threading approach.

More about threading : 
Python threading was different before the 3.2 version the sharing of the control between threads was by using the Ticks method where the thread checks if there is any other thread asking for thread control after 100 ticks. This method was tedious. There were issues like :
1. Starvation
2. Signaling overhead to tell thread has finished task.
3. Battle for GIL

But with a fixed time approach of 5ms for all the threads, it removes all three issues which used to be in the previous version. But it also has one major disadvantage. It has the property of having priority of CPU bound operation more than I/O bound operation but in fact, we need more priority to I/O operation. So this leads to a problem of Priority Inversion.

This is not to say that Python cannot execute truly multithreaded, parallel code. Python C extensions that use native multithreading (in C or C++) can run code in parallel without being impacted by the GIL, so long as they do not need to regularly interact with Python objects.

This is very necessary to understand the inner level of programming language, how it is built and it's architecture because it makes you understand what are the language speciality and where the language shorts.

Comments

Popular posts from this blog

Digital Currency

 First of all, let's understand what is digital currency? Digital currency are currency with no physical attributes and are available only in digital form. So if we need to do transaction with them we use computers or electronic wallets which should be connected to internet or a particular network.  Types: Central bank Digital Currency : regulated by central bank of a country. It can somewhat replace or be an alternative to traditional fiat currency. China has e-CNY, a digital version of fiat currency. Virtual Currencies : unregulated digital currency that is controlled by developers or founding organization. An example of this is gaming token whose economics is defined and controlled by developers. Cryptocurrencies : They are digital currency that use cryptography to secure and verify transactions in a network. They may or may not be regulated depending on the law and policy of different countries. Benefits of Digital Currency : - They are very fast in transaction as they are...

Prerequisite for Data Science Developers in Python

Data Science is a very important job in today's age of data being the aspect that plays a vital role in most of the field whether it may be the medical field, business, agriculture, engineering, sports and the list go on and on. Python is one of the programming language, which is used for data science and machine learning. It consists of many libraries and a very good community built within the past couple of decades. And it also has the upper hand among other languages as this same language can be used to build the system. While I talk about libraries in Python for Data Science(DS), the first library that come into thought is "NumPy", NumPy (abbreviation for Numerical Python) is the library built with the purpose of scientific calculation in numerical data. It is best for storing the numerical values in an array as a NumPy array that may be single or multi-dimensional (also called Tensors). "Okay, then why not List?"  T...

Why Social Media is good for you?

"Social Media is ruining our generation" you must have heard this sentence hundred time if not more. Infinity scroll feed in our fingertips have changed our life. But is this change only effecting us in bad way? While social media can make us hung in our phone for long long hours with dopamine hit, it also has some good deeds to us which we often fail to look on. The number of new business model and ideas that social media has brought today cannot be ignored. But today I am going to talk the different part that social media has helped humans on. One of the most important thing, it helped us is, today information is accessible to all the people. Every person on earth with smartphone and internet connection have access to news and updates from all over the world. In previous time, for one to learn new things they need first accumulate the motivation to gain knowledge then find the resource (which were not easily accessible) like books, magazines, videos, etc. But today, if the...