GIL(Global Interpreter Lock)は CPython(標準的な Python 実装)に存在するミューテックスで、一度に 1 つのスレッドしか Python バイトコードを実行できないようにします。つまり Python のスレッドは複数の CPU コア上で Python コードを真に並列実行できず、並行処理を考えるうえで重要な要素となります。
GIL が実際に意味すること
Even with multiple threads on a multi-core CPU:
Only ONE thread runs Python bytecode at any instant.
→ Threading does NOT give CPU-bound parallelism in CPython.
重要な区別: CPU バウンド vs I/O バウンド
threading
():
(i * i i ())
():
response = requests.get(url)
