Logging in a File
Logging to a File As we saw in the previous blog, Python allows us to store our log onto a file. Python offers two ways in which we can do this: Using the ‘filename’ parameter from the basicConfig() function. Using the FileHandler() function. Using basicConfig() As seen in the previous blog, the ‘filename’ parameter…
Basic Configurations in Logging
Basic Configurations The logging module offers a function called ‘basicConfig’ which allows us to configure how we log our code. This function has quite a few parameters which we can alter to modify the default behavior of our logs. We saw the debug(), info(), warning(), error(), and critical() function in the previous blog, but what…
Logging
Logging Logging is a powerful way to help us develop a better understanding of the flow of our program while opening up ways to see different perspectives in the way we developed our code. Loggins is a method by which we can track different events that happen when our program is being executed. An event…
Barrier Object
Barrier The Barrier object allows us to make two or more threads wait till a certain condition has been met. We achieve this using the wait() function, and each of the threads tries to pass over the wait() function but all attempts to pass over it will be blocked till all of the threads have…
Condition Object
Condition The condition object allows us to run a thread only if a requirement is met in another thread, and once it’s met, we can inform the waiting thread that the requirement has been met. A real-life scenario of this would be; that a producer has run out of products in his store, now the…
Event and Timer Object
Event When using Threads there are situations when we want the thread to wait for some time and then continue execution. We can achieve this with the use of the Event object. An event is signaled from one thread while another waits for the event to be signaled. One of the aims of using an…
Lock and Rlock Object
Lock Another important feature that we need to remember when using Threads is the mechanism of locking. Imagine if you are using multiple threads on a single resource, when one thread updates the shared resource, another thread may also make some modifications to the shared resource. For example, imagine if multiple employees are using a…
Thread Object
Thread Object In the previous blog we used an object of the class Thread to create and start a thread, as shown below: variable = threading.Thread(target=function_name, args=[1]) Let us take a closer at the Thread class. The most frequently used aspect of the threading module is the Thread class. The Thread class allows us to…
Threading Module in Python
Threading Let us explore the Threading module. Firstly let’s look at an example of how much time a code takes to run when we do not use threading and when we do use threading. import time # starting a counter start = time.perf_counter() def sleeper_function(sleep_length): print(“Going to sleep now:”) time.sleep(sleep_length) …
Introduction to Multithreading
Multithreading When we run a block of code, let’s say a ‘While’ loop, the program is now halted till this loop has reached completion. In other words, we cannot execute two blocks of code simultaneously. To achieve multitasking using programming we need to use threading, or specifically Multithreading. The concept of threading allows us…