threading

Multithreading or threading is the solution to running ‘several processes’ at once. Threading gives us parallel execution.

Note: it’s not truly paralel as the operating system still executes thread sequentially.

Related course: Complete Python Bootcamp: Go from zero to hero in Python

Threading example

we use the modules threading and queue to start several threads. A queue is created by calling Queue(). Then we have an array of urls as parameter for thread construction.

Threads are created in the for loop using the call threading.Thread(). Then they have to be started by calling thead.start(). Every thread calls the method getUrl.

Graphically this is what happens. Your program (the main thread) starts several new threads which execute a task “in parallel”.

multithreading in python

A program can have any number of threads, each of which work on some data.

Previous Post

Leave a Reply