Multithreading – convenient but full of surprises
We already worked with multithreading (see Chapter 5, Retrieving and Handling Market Data with Python, the Universal data connector section), and we found that using multiple threads makes life way easier when we develop modular scalable applications. However, we never explored how multithreading is implemented in Python.
Two concepts are frequently confused: multiprocessing and multithreading. The difference between them is that the former uses the concept of isolated processes, each of them having a global interpreter lock (GIL), thus enabling parallel execution using separate physical or logical processors or processor cores (so-called true parallelism), whereas the latter runs a single process that doesn’t care about the number of processors or cores: it executes threads in small portions, allowing each thread to run for several milliseconds and then switching to another one. Of course, from a human perspective...