So I recently encountered another shocking and sad accident in my code, which is the race condition introduced by using singleton. I used to think singleton is good for storing things that only exist one copy in the system and can be reused. I saw a few of programs store their Redis connection pool in a singleton class, which looks nice. Then bad thing happens when I use that SDK I wrote in a Flask service with multithread enabled and save user states inside singleton. Then race condition happens, before one session finished, another already came in and overwrote the states. I would say from now I would really be extra meticulous about any designs and patterns I feel good about and then judge them before I put them in any running services. And for the solution? Actually it was quite straightforward, just save the states in each client object, no other tricks. Here is an example from Supervisely, which is an MLops platform which also support running services with their SDK as part of the code. https://lnkd.in/gc9bD8U7 #python #race_condition #singleton
Yue Wang’s Post
More Relevant Posts
-
When I first saw our production database hitting 99% utilization, I thought we needed a bigger server. I was wrong. The real problem wasn’t infrastructure. It was one unoptimized query quietly running inside a loop. Development was fast. Production exposed everything. I just published a deep dive on Django Query Optimization — covering N+1 problems, select_related vs prefetch_related, aggregations, indexing strategies, and real-world mistakes that slow apps down. here is my article link https://lnkd.in/gViDwwVd If you’re building APIs in Django, this might save you from a painful production incident. Would love to know: Have you ever faced a performance issue that wasn’t obvious at first? #Django #BackendDevelopment #Python #DatabaseOptimization #WebPerformance
To view or add a comment, sign in
-
-
Excited to release plyra-guard — open-source action middleware for AI agents. The problem: agents take real-world actions with no safety layer between the LLM's decision and execution. plyra-guard intercepts every tool call before it runs — policy engine, full audit log, built-in dashboard. Sub-2ms overhead, works with every major framework. pip install plyra-guard Apache 2.0. 217 tests. Python 3.11–3.13. Check out the link in Comments! #AgenticAI #Python #OpenSource #LLM
To view or add a comment, sign in
-
-
Built a URL shortener in C from scratch Not in Python, Not with a framework. Raw C, custom HTTP server and SQLite for persistence. At first it worked fine, but under load? Every redirect = a database read. Every database read = disk I/O. At scale, this is the bottleneck. What worked? An in-memory LRU cache in front of SQLite (sounds tempting but its not). The result: i) Frequently accessed URLs served from memory ii) SQLite reads dropped significantly around iii) Latency on hot URLs got much faster | 2x faster Most real-world URL traffic follows a power law. A small percentage of URLs get the majority of hits and a cache exploits exactly that pattern. Github: https://lnkd.in/gshFUnFj
To view or add a comment, sign in
-
-
Migrated from Node.js (Express) to FastAPI Recently, I rebuilt one of my APIs from Node.js to FastAPI — and here’s what changed: 🔹 Manual validation → ✅ Pydantic models 🔹 Custom Swagger setup → ✅ Auto-generated docs 🔹 More boilerplate → ✅ Cleaner & structured code 🔹 Middleware logic → ✅ Dependency Injection ⚡ Performance: FastAPI felt faster and more structured (especially with Python typing). 🛠 Maintenance: Easier due to built-in validation & documentation. If you're working with Python or ML stack, FastAPI is a solid choice for modern APIs. #Backend #FastAPI #NodeJS #Python #APIDevelopment
To view or add a comment, sign in
-
-
I put together a local text-to-speech project using Qwen3-TTS, wrapped in a C# console app and run inside Docker. It takes text from the command line, generates MP3 or WAV files, supports custom output names, and lets you override the voice and speaking style for each run. The repo is set up with the source folder mounted into the container, so code changes are available on the next run without rebuilding the image unless dependencies change. It’s a practical example of combining .NET, Python, Docker, and local AI in a development workflow. Repository: https://lnkd.in/eDuDbjdf #dotnet #csharp #python #docker #ai #tts #machinelearning #opensource
To view or add a comment, sign in
-
Currently working through a Flask tutorial. At this stage, I’ve been learning and implementing: • Flask routing and request handling (GET vs POST) • User authentication and session management • Extending data models and handling migrations • Server-side forms with validation • Tracking user activity with UTC timestamps • Using Jinja templates and template inheritance It’s been helpful in understanding how backend logic, database state, and templates come together in a real Flask application. #Python #Flask #WebDevelopment #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
Bokeh, Origin Validation Bypass, CVE-2026-21883 (Medium) CVE-2026-21883 is a vulnerability in the Bokeh interactive visualization library for Python, specifically affecting versions 3.8.1 and below . The flaw resides in the server's `match_host` function within server/util.py, which is responsible for validating WebSocket connection origins against an administrator-defined allowlist (e.g., dashboard.corp) . The vulnerability arises because the validation logic uses Python's `zip()` function to compare the hostname parts against the pattern....
To view or add a comment, sign in
-
Bokeh, Origin Validation Bypass, CVE-2026-21883 (Medium) CVE-2026-21883 is a vulnerability in the Bokeh interactive visualization library for Python, specifically affecting versions 3.8.1 and below . The flaw resides in the server's `match_host` function within server/util.py, which is responsible for validating WebSocket connection origins against an administrator-defined allowlist (e.g., dashboard.corp) . The vulnerability arises because the validation logic uses Python's `zip()` function to compare the hostname parts against the pattern....
To view or add a comment, sign in
-
Dworshak configuration ecosystem rising. Now with libraries and CLI sub apps for: - dworshak-secret - dworshak-config - dworshak-env - dworshak-prompt It has never been easier to reach your users (or yourself) for cross-platform, stable credentials and config values scripted in your Python code and also managed with the `dworshak` CLI. Come see what we are up to. https://lnkd.in/ey5M2Bnc
To view or add a comment, sign in
-
-
What is Dependency Injection? DI is a design pattern where an object receives what it needs (DB session, client, cache, config) instead of creating those dependencies itself. That small shift pays off: - looser coupling (swappable implementations) - easier testing (fake/stub dependencies) - cleaner architecture (objects do one job) In Python, DI often turns into either manual wiring everywhere or heavy frameworks. That's why we built #diwire: An extremely fast type-driven DI container for Python that builds your object graph from type hints with dependencies, scopes + deterministic cleanup, async support, and integrations with the most popular libraries (FastAPI, Pydantic, and more). If you want a concrete "this is how it looks in a real app" example, start here: GitHub: https://lnkd.in/gshHbkWP Integrations docs: https://lnkd.in/gDz_Phya
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