Skip to content

Commit a131715

Browse files
author
Hong
committed
Update docs
1 parent 09bf53d commit a131715

File tree

1 file changed

+23
-0
lines changed
  • docs/computer languages/programming_languages/python

1 file changed

+23
-0
lines changed

docs/computer languages/programming_languages/python/python.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@
77
* interpreter implementation for python
88
* CPython
99

10+
## Q&A
11+
12+
1. What is a key difference between multi-threading and multi-processing in Python?
13+
A. Multi-threading uses multiple CPUs, while multi-processing uses a single CPU.
14+
B. Multi-threading is limited by the GIL, while multi-processing bypasses it.
15+
C. Multi-threading is faster for CPU-bound tasks, while multi-processing is faster for I/O-...
16+
17+
Answer:
18+
It should be B. Multi-threading is limited by the GIL, while multi-processing bypasses it.
19+
20+
From Python docs:
21+
22+
* [Python docs/3.13.1/threading — Thread-based parallelism](https://docs.python.org/3.13/library/threading.html)
23+
* CPython implementation detail: In CPython, due to the Global Interpreter Lock, only one thread can execute Python code at once (even though certain performance-oriented libraries might overcome this limitation). If you want your application to make better use of the computational resources of multi-core machines, you are advised to use multiprocessing or concurrent.futures.ProcessPoolExecutor. However, threading is still an appropriate model if you want to run multiple I/O-bound tasks simultaneously.
24+
25+
* [Python docs/3.13.1/multiprocessing — Process-based parallelism](https://docs.python.org/3/library/multiprocessing.html)
26+
* multiprocessing is a package that supports spawning processes using an API similar to the threading module. The multiprocessing package offers both local and remote concurrency, effectively side-stepping the Global Interpreter Lock by using subprocesses instead of threads. Due to this, the multiprocessing module allows the programmer to fully leverage multiple processors on a given machine. It runs on both POSIX and Windows.
27+
28+
* [Python docs/GIL global interpreter lock](https://docs.python.org/3/glossary.html#term-global-interpreter-lock)
29+
* The mechanism used by the CPython interpreter to assure that only one thread executes Python bytecode at a time. ...
30+
* More details, please click all of these URL links or do somtheing coding test to prove these ideas.
31+
32+
1033
## docs/news/guides/tips/misc...
1134

1235
* [VizTracer is a low-overhead logging/debugging/profiling tool that can trace and visualize your python code execution.](https://github.com/gaogaotiantian/viztracer)

0 commit comments

Comments
 (0)