Skip to content

Commit

Permalink
Minor Examples: Update explanation for multithreading example
Browse files Browse the repository at this point in the history
* Clarifies that Python threads do run concurrently and are
  useful for I/O bound tasks.

Fixes satwikkansal/wtfpython#30
  • Loading branch information
tothetop430 committed Sep 6, 2017
1 parent ebc77fc commit 7d1282f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d1282f

Please sign in to comment.