Comment

Comment by justinl33

Python's module loading mechanism is thread-safe by default, and module-level variables are effectively singletons. This would suffice:

_connection = None

def get_connection(): global _connection if _connection is None: _connection = create_connection() return _connection

parent justinl33 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton