𝗤. 𝗜𝗳 𝗣𝘆𝘁𝗵𝗼𝗻 𝗛𝗮𝘀 𝗧𝗵𝗿𝗲𝗮𝗱𝘀… 𝗪𝗵𝘆 𝗗𝗼𝗲𝘀𝗻’𝘁 𝗜𝘁 𝗦𝗰𝗮𝗹𝗲 𝗼𝗻 𝗠𝘂𝗹𝘁𝗶𝗽𝗹𝗲 𝗖𝗼𝗿𝗲𝘀? When I first learned about multithreading in Python, I assumed it would use all CPU cores. It doesn’t (for CPU-heavy tasks). The reason is something called the 𝐆𝐥𝐨𝐛𝐚𝐥 𝐈𝐧𝐭𝐞𝐫𝐩𝐫𝐞𝐭𝐞𝐫 𝐋𝐨𝐜𝐤 (𝐆𝐈𝐋). 👉 The GIL ensures that only one thread executes Python bytecode at a time. So even if you create multiple threads: CPU-bound tasks won’t run in parallel They take almost the same time as a single thread But here’s the important nuance:- The GIL mainly affects 𝐂𝐏𝐔-𝐛𝐨𝐮𝐧𝐝 𝐭𝐚𝐬𝐤𝐬. For: - I/O-bound work (API calls, file reading, DB queries) - Network operations - Threading still improves performance. So how do we use multiple cores in Python? -> multiprocessing -> ProcessPoolExecutor -> Libraries like NumPy (which release GIL internally) My takeaway: 𝐔𝐧𝐝𝐞𝐫𝐬𝐭𝐚𝐧𝐝𝐢𝐧𝐠 𝐆𝐈𝐋 𝐜𝐡𝐚𝐧𝐠𝐞𝐬 𝐡𝐨𝐰 𝐲𝐨𝐮 𝐝𝐞𝐬𝐢𝐠𝐧 𝐬𝐲𝐬𝐭𝐞𝐦𝐬 𝐢𝐧 𝐏𝐲𝐭𝐡𝐨𝐧. #Python #TechInterview #SoftwareEngineering #LearningInPublic #SystemDesign
Also for efficiency purposes, need to focus performatively on how even a single thread execution of tasks is taking place whether it is non-blocking or blocking fashion.
lowkey i am even happy if my model atleast bite at the data , going stuff like optimization is way way above my pay grade.
Waiting for packages to get version updates that works with python 3.14.