__name__ Variables

__name__ Variable Dunder In Python, we have what we call ‘dunder’ names, and it refers to a naming convention that uses double underscores at the start and end of the variable or function. The term ‘dunder’ means double underscores. The term ‘__name__’ is a special variable in Python which refers to the current script that…

Logging Classes and Functions

Logging Classes & Functions So far, we have seen how we can create logs as well as how to write logs to a file. When creating logs we saw the term ‘logger’ when we discussed the name of the log, as well as creating a log using the FileHandler() function. Let’s dive deeper into what…

Logging Varriable Data

Variable Data When creating logs it will be useful if we had the option to use variables to make a more meaningful log record. While we can create variables that hold our string, we can also create logs that directly access a variable we require. import logging user_name = “Christopher” logging.warning(“%s encountered a warning message”,…

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…