1
0
mirror of https://github.com/satwikkansal/wtfpython synced 2024-11-22 02:54:25 +01:00

Minor Examples: Update explanation for multithreading example

* Clarifies that Python threads do run concurrently and are
  useful for I/O bound tasks.

Fixes https://github.com/satwikkansal/wtfpython/issues/30
This commit is contained in:
Satwik Kansal 2017-09-06 16:20:54 +05:30
parent 24c4a6469e
commit cc3eb36f92

2
README.md vendored
View File

@ -1661,7 +1661,7 @@ a, b = a[b] = {}, 5
print(dis.dis(f))
```
* Multiple Python threads don't run concurrently (yes you heard it right!). It may seem intuitive to spawn several threads and let them execute concurrently, but, because of the Global Interpreter Lock in Python, all you're doing is making your threads execute on the same core turn by turn. To achieve actual parallelization in Python, you might want to use the Python [multiprocessing](https://docs.python.org/2/library/multiprocessing.html) module.
* Multiple Python threads won't run your *Python code* concurrently (yes you heard it right!). It may seem intuitive to spawn several threads and let them execute your Python code concurrently, but, because of the [Global Interpreter Lock](https://wiki.python.org/moin/GlobalInterpreterLock) in Python, all you're doing is making your threads execute on the same core turn by turn. Python threads are good for IO-bound tasks, but to achieve actual parallelization in Python for CPU-bound tasks, you might want to use the Python [multiprocessing](https://docs.python.org/2/library/multiprocessing.html) module.
* List slicing with out of the bounds indices throws no errors
```py