

The main difference with the two others else than providing more interfaces, is its ability to serialize and de-serialize data using a third-party library called pickle.

Multiprocessing is the most complete library that can provide threading capabilities. The sleep function, whose purpose is to… sleep. The three laureates are: Threads, Thread Pools, and Multi-Processing.įor clarity, let’s first introduce the function that we wish to parallelize. Let’s digress a bit and analyze the different possibilities Python offers to run computation in parallel. It is a very powerful tool that can allow faster computation or the ability to handle concurrent events (think of robots with multiple sensor data to process). For example we can share some variables between threads or we can wait for the threads to finish, merge the results and go on with the rest of the code. However it is different than just executing two programs at the same time since threads give us more control.
#SWIFT SHARE VARIABLE BETWEEN THREADS CODE#
The particularity of threads versus processes is that they can share variables.įor us in terms of coding, when we run two threads, we allow two pieces of code to run at the same time. Each of them has a set of instructions(open your browser or increase the volume) that it wants to have read by the scheduler (the referee that decides what to feed to the processor). When you run two programs on your computer, you actually create two processes. What is a thread? It’s a lightweight process that runs on your computer, executing it’s own set of instructions.
