TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Shades of Singleton design pattern – Python

3 pointsby yashness4 months ago

1 comment

justinl334 months ago
Python&#x27;s module loading mechanism is thread-safe by default, and module-level variables are effectively singletons. This would suffice:<p>_connection = None<p>def get_connection(): global _connection if _connection is None: _connection = create_connection() return _connection
评论 #42610112 未加载