Skip to main content
added 178 characters in body
Source Link

Two things:

  1. GIL is released from time to time. For example when you try to execute some lengthy operation (read from file, write to file, send over network and so on). This allows for some interleaved operations - read in one thread, process in another.

  2. Multithreading is not only performance, there're other benefits - for example easiness of expression. Imagine you've two algorithms running in "parallel", which communicate with each other and exchange data. You put each algorithm on it's own thread, synchronize (to make sure thread switch will happen when it can) and off you go. Without multithreading you'd have to rely on event programming, which is difficult and easily scalable. The good example for this are various kinds of session based servers, for example ftp server. It's much easier to write multithreaded multiuser ftp server, than single threaded.

In general yes, if you use threads for performace then python's threads don't make sense. But python is not used for performance, but for how easy it's to write (and modify) code. And threads do help for parallel code a lot, even if they don't offer any multhreading performance benefits.

Two things:

  1. GIL is released from time to time. For example when you try to execute some lengthy operation (read from file, write to file, send over network and so on). This allows for some interleaved operations - read in one thread, process in another.

  2. Multithreading is not only performance, there're other benefits - for example easiness of expression. Imagine you've two algorithms running in "parallel", which communicate with each other and exchange data. You put each algorithm on it's own thread, synchronize (to make sure thread switch will happen when it can) and off you go. Without multithreading you'd have to rely on event programming, which is difficult and easily scalable.

In general yes, if you use threads for performace then python's threads don't make sense. But python is not used for performance, but for how easy it's to write (and modify) code. And threads do help for parallel code a lot, even if they don't offer any multhreading performance benefits.

Two things:

  1. GIL is released from time to time. For example when you try to execute some lengthy operation (read from file, write to file, send over network and so on). This allows for some interleaved operations - read in one thread, process in another.

  2. Multithreading is not only performance, there're other benefits - for example easiness of expression. Imagine you've two algorithms running in "parallel", which communicate with each other and exchange data. You put each algorithm on it's own thread, synchronize (to make sure thread switch will happen when it can) and off you go. Without multithreading you'd have to rely on event programming, which is difficult and easily scalable. The good example for this are various kinds of session based servers, for example ftp server. It's much easier to write multithreaded multiuser ftp server, than single threaded.

In general yes, if you use threads for performace then python's threads don't make sense. But python is not used for performance, but for how easy it's to write (and modify) code. And threads do help for parallel code a lot, even if they don't offer any multhreading performance benefits.

Source Link

Two things:

  1. GIL is released from time to time. For example when you try to execute some lengthy operation (read from file, write to file, send over network and so on). This allows for some interleaved operations - read in one thread, process in another.

  2. Multithreading is not only performance, there're other benefits - for example easiness of expression. Imagine you've two algorithms running in "parallel", which communicate with each other and exchange data. You put each algorithm on it's own thread, synchronize (to make sure thread switch will happen when it can) and off you go. Without multithreading you'd have to rely on event programming, which is difficult and easily scalable.

In general yes, if you use threads for performace then python's threads don't make sense. But python is not used for performance, but for how easy it's to write (and modify) code. And threads do help for parallel code a lot, even if they don't offer any multhreading performance benefits.