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 = Nonedef get_connection(): global _connection if _connection is None: _connection = create_connection() return _connection parent justinl33 1 year ago
_connection = None
def get_connection(): global _connection if _connection is None: _connection = create_connection() return _connection