threads most oftenconcurrency is created so that work can continue happening while the program is waiting for / to happen for examplea server can start processing new network request while it waits for data from previous request to arrive an interactive program might render an animation or perform calculation while waiting for the user to press key bear in mind that while person can type more than characters per minutea computer can perform billions of instructions per second thusa ton of processing can happen between individual key presseseven when typing quickly it' theoretically possible to manage all this switching between activities within your programbut it would be virtually impossible to get right insteadwe can rely on python and the operating system to take care of the tricky switching partwhile we create objects that appear to be running independentlybut simultaneously these objects are called threadsin python they have very simple api let' take look at basic examplefrom threading import thread class inputreader(thread)def run(self)self line_of_text input(print("enter some text and press enter"thread inputreader(thread start(count result while thread is_alive()result count count count + print("calculated squares up to { { { }formatcountresult)print("while you typed '{}'format(thread line_of_text)this example runs two threads can you see themevery program has one threadcalled the main thread the code that executes from the beginning is happening in this thread the second threadmore obviouslyexists as the inputreader class to construct threadwe must extend the thread class and implement the run method any code inside the run method (or that is called from within that methodis executed in separate thread