I have always been a huge fan of concurrent programming and famous sitcom television series The Office . In this blog I am trying to relate multi-threading in Python with different episodes of The office.

THREADS

In sequential programming, like a program (process) to print “Hello World!”, the program has a start, a set of sequence of instructions to execute and an end.

Image for post

Just like sequential programming, a thread has a start, a set of sequence of instructions to execute and an end. But threads cannot coexist without a process. In other words, threads are a subset of a process. Operating system schedules execution of the threads based on a scheduling algorithm.

Image for post

As an analogy one can visualize television series “The Office” as a process and every character in the television series as an individual thread. The office show has a beginning, a set of sequence of instructions (or episodes) and an end, just like each of the characters (threads). Characters play their part and are terminated either when the script demands (operating system)or when the show ends (process).


LIFECYCLE OF A THREAD

Image for post

Broadly speaking thread has 4 states. New, when thread is defined. Runnable is when it has all the resources required to go into execution state.Waiting, when thread is waiting for a resource and Terminated when thread is done with execution.

#python #python-programming #multithreading

Python Multi-Threading and the Office
1.40 GEEK