😵 Thread-local storage works great... until you move to async. Then the weird stuff starts. Request IDs bleeding between coroutines. Background tasks sharing state. “Random” bugs that disappear under logging. Sound familiar? Async doesn’t care about threads. It cares about execution context. In my latest article I explain: 🔍 Why threading.local() fails under asyncio 🧠 How ContextVars isolate state per coroutine ⚙️ Real examples with async tasks and request-scoped data 👉 https://lnkd.in/d_aVTDtW #python #softwaredevelopment #backend #engineering #asyncio
Chris Karvouniaris’ Post
More Relevant Posts
-
𝗬𝗼𝘂 𝗮𝗱𝗱𝗲𝗱 𝘁𝗵𝗿𝗲𝗮𝗱𝘀 𝘁𝗼 𝘀𝗽𝗲𝗲𝗱 𝘂𝗽 𝘆𝗼𝘂𝗿 𝗖𝗣𝗨-𝗯𝗼𝘂𝗻𝗱 𝗰𝗼𝗱𝗲. 𝗜𝘁 𝗴𝗼𝘁 𝘀𝗹𝗼𝘄𝗲𝗿. Don't blame Python. Blame the GIL (Global Interpreter Lock). The GIL ensures only one thread executes Python bytecode at a time. This is a safety feature, but for CPU-heavy tasks, it creates a bottleneck. Your threads aren't "working together"—they're fighting for the lock. The result? More overhead, zero speedup. The Rule of Thumb: 🔹 𝗜/𝗢-𝗯𝗼𝘂𝗻𝗱 (API calls, DB queries): Use 𝗧𝗵𝗿𝗲𝗮𝗱𝗣𝗼𝗼𝗹𝗘𝘅𝗲𝗰𝘂𝘁𝗼𝗿. Threads release the GIL while waiting for the network. 🔹 𝗖𝗣𝗨-𝗯𝗼𝘂𝗻𝗱 (Compression, Image processing): Use 𝗣𝗿𝗼𝗰𝗲𝘀𝘀𝗣𝗼𝗼𝗹𝗘𝘅𝗲𝗰𝘂𝘁𝗼𝗿. Each process gets its own Python instance and its own GIL. 🔹 Python 3.13 ships with an experimental no-GIL build — not production-ready, but the direction is clear Same interface, opposite internals. The decision is made at the Executor level — not scattered across your codebase #Python #SoftwareEngineering #BackendDevelopment #Concurrency #SoftwareArchitecture
To view or add a comment, sign in
-
-
I built a Python script that organized my entire Downloads folder in under 3 seconds. Here's the embarrassing truth : my Downloads folder had 100+ files. PDFs, random images, zip files, old code. All just sitting there. A complete mess. So instead of cleaning it manually (again), I wrote a Python script to do it for me. What it does: → You point it at any folder → It scans every file → Sorts them into Images, Videos, Documents, Code, Archives → Shows a preview before touching ANYTHING → Logs every move with a timestamp What I learnt building this: → pathlib makes file/folder handling so much cleaner than I expected → sys.exit() is how you kill a program gracefully instead of just crashing → mkdir() creates folders on the fly if they don't exist in a single line The part I'm most proud of is that it asks for confirmation before moving anything, so you never accidentally mess something up. Full code on GitHub: https://lnkd.in/gCwyzJAv 🤘 #Python #Automation #7DaysOfPython #100DaysOfCode
To view or add a comment, sign in
-
There's been an explosion of open-source Python type checkers and language servers recently. Now you're not locked into Pylance! I wrote about the state of the LSP world today, and why you should still care about them even if AI writes all your code: https://lnkd.in/gusUZybX
To view or add a comment, sign in
-
PyFuncAI Launches LLM-Generated Python Functions at Runtime 📌 PyFuncAI lets LLMs dynamically generate and run Python functions at runtime-no static toolsets needed. Developers can now build flexible AI agents that solve novel problems on the fly, reducing maintenance overhead while keeping code adaptable. Perfect for agentic systems craving real-time, adaptive logic. 🔗 Read more: https://lnkd.in/d_W49MNx #Pyfuncai #Llmgenerated #Pythonruntime #Naturallanguage #Functionsynthesis
To view or add a comment, sign in
-
Python is often called slow. Mostly because it’s an interpreted language. But here’s what gets missed. Speed at the language level is only one part of the system. In real applications, performance depends more on architecture, I O handling, and how workloads are designed. That’s why Python continues to power AI systems, data platforms, automation tools, and large-scale backends. Heavy computation is often offloaded to optimized libraries or handled outside the main runtime. The rest is about writing efficient, structured code. So yes, Python is slower at a low level. But that rarely becomes the bottleneck in real systems. Time to break the myth. #MadForCoding #Python #SoftwareEngineering #BackendDevelopment #TechMyths #SystemDesign
To view or add a comment, sign in
-
-
Experimented with OpenClaw using local Ollama but performance was horrible (each response taking up 1.5+ minutes), so ended up writing a Python script for the task I had in mind for it instead. Uses Google OAuth to get access to Gmail, goes through recent messages and marks anything that doesn't look important as read. https://lnkd.in/gAHcxcdv #MinorInconveniencePatches : #3
To view or add a comment, sign in
-
Scale vector search to millions without rewriting your prototype code ⚡ Building semantic search typically starts with storing vectors in Python lists and computing cosine similarity manually. But brute-force comparison scales linearly with your dataset, making every query slower as your data grows. Qdrant is a vector search engine built in Rust that indexes your vectors for fast retrieval. Key features: • In-memory mode for local prototyping with no server setup • Seamlessly scale to millions of vectors in production with the same Python API • Built-in support for cosine, dot product, and Euclidean distance • Sub-second query times even for millions of vectors ☕️ Run this code: https://bit.ly/4cCI76w #VectorDatabase #Python #SemanticSearch #DataScience
To view or add a comment, sign in
-
-
Practiced Python functions today — *args, **kwargs, return types, and function types. The one thing that clicked — *args is for unknown number of values (stores as tuple), **kwargs is when you don't know the keys either (stores as dict). Simple but I was mixing them up before. Also learned there are actual types of functions — action, transformation, validation. https://lnkd.in/ducSzXzK #Python #LearningInPublic #DataAnalysis
To view or add a comment, sign in
-
Learning FastAPI and it’s surprisingly elegant. Today I explored: • API routing • Request validation with Pydantic • Dependency Injection • Async handlers The developer experience is insanely good. #Python #FastAPI #Backend #LearnInPublic
To view or add a comment, sign in
-
Just practiced Pandas and data cleaning hits different when you're working with real messy data. Covered data types, type conversion, handling missing values, replacing inconsistent entries, and using category dtype to save memory — FuelType column went from 11488 bytes to 1460 bytes just by changing the dtype. Notebook here 👉 https://lnkd.in/d3djYPvp #Python #Pandas #DataAnalysis #LearningInPublic
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development