You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: concurrency/README.rst
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,28 +8,23 @@ good reasons to be very cautious with it.
8
8
9
9
----
10
10
11
-
Why is Concurrency risky?
12
-
-------------------------
11
+
Pros and Cons of Concurrency
12
+
----------------------------
13
13
14
-
Many times, the devil is so much in the details that it is even a bad idea.
14
+
Often concurrency is a bad idea. The devil is lurking in the details:
15
15
16
16
- Coordinating parallel sub-programs is very difficult to debug (look up the words *“race condition”* and *“heisenbug”*).
17
-
- Starting multiple Python processes instead is really easy (e.g. from a batch script or the `multiprocessing` module).
18
17
- Python has a strange thing called the **GIL (Global Interpreter Lock)**. That means, Python can really only execute one command at a time.
19
-
- There are great existing solutions for the most typical applications.
18
+
- There are great existing solutions for many typical applications (web scraping, web servers).
20
19
21
-
----
22
-
23
-
When could concurrency be a good idea?
24
-
--------------------------------------
20
+
On the other hand, concurrency can be a good idea:
25
21
26
-
Here is one example:
22
+
- if your tasks are waiting for some I/O anyway, the speed of Python does not matter.
23
+
- starting multiple separate Python processes is rather easy (with the `multiprocessing` module).
24
+
- if you are looking for a challenge.
27
25
28
-
You are writing a computer game for fun and would like many sprites to
29
-
move at the same time **AND** you are looking for difficult problems to solve.
30
-
31
-
There are two noteworthy approaches to concurrency in Python:
32
-
**threads** and **coroutines**.
26
+
There are three noteworthy approaches to concurrency in Python:
27
+
**threads**, **coroutines** and **multiple processes**.
33
28
34
29
----
35
30
@@ -64,14 +59,19 @@ This is the most flexible approach, but also has the highest overhead.
64
59
65
60
.. literalinclude:: factorial.py
66
61
67
-
68
62
----
69
63
70
-
Alternatives
71
-
------------
64
+
Challenge: Gaussian Elimination
65
+
-------------------------------
66
+
67
+
In :download:`gauss_elim.py` you find an implementation of the `Gauss Elimination Algorithm <https://en.wikipedia.org/wiki/Gaussian_elimination>`__ to solve linear equation systems.
68
+
The algorithm has a **cubic time complexity**.
69
+
70
+
Parallelize the execution of the algorithm and check whether it gets any faster.
71
+
72
+
In :download:`test_gauss_elim.py` you find unit tests for the module.
72
73
73
-
- if you want to read/write data, use a database
74
-
- if you want to scrape web pages, use the ``scrapy`` framework.
75
-
- if you want to build a web server, use ``FastAPI`, ``Flask`` or ``Django``.
76
-
- if you want to do number crunching, use ``Spark``, ``Dask``, ``Pytorch`` or ``Tensorflow``
74
+
.. note::
77
75
76
+
The linear equation solver is written in plain Python.
77
+
Of course, Numpy would also speed up the execution considerably.
0 commit comments