Disadvantages

However, there are some disadvantages with multithreading. Some are inherent in the multithreading paradigm, and others (such as GIL), are particular to Python:

  • Threads cannot directly start another program. They can only call functions or methods in parallel with the rest of the program that spawned them, that is, threads can only utilize and interact with the components of their parent but can't work with other programs.
  • Threads have to contend with synchronization and queues to ensure operations don't block others. For example, there is only one stdin, stdout, and stderr available per program and all the threads for that program have to share those interfaces, so managing thread conflicts can become a problem.
  • Global interpreter lock (GIL) is the bane of many thread programmers. Simply put, GIL prevents multiple threads from operating within the Python interpreter environment simultaneously. While the OS may have dozens or hundreds of threads, Python programs can only utilize the Python environment one at a time. When a Python thread wants to do work, it must lock down the interpreter until the work is over. Then, the next thread in line gains access to the interpreter and locks it in turn. In other words, you can have multithreading but you can't have true, simultaneous operations. Because of this, threads can't be split across multiple CPUs; you can only have multithreading within one CPU.
  • Shared memory means a crashed/misbehaving thread can trash data and corrupt the parent process.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset