mirror of
https://github.com/mcp-use/mcp-use.git
synced 2026-09-14 18:06:01 +08:00
cb7c2bcbd6
* Telemetry base * Fix debug level * Singleton pattern in utils for metric server * Added public identifier to transports * Update telemetry * Add telemetry to mcpagent * telemetry docs
28 lines
720 B
Python
28 lines
720 B
Python
def singleton(cls):
|
|
"""A decorator that implements the singleton pattern for a class.
|
|
|
|
This decorator ensures that only one instance of a class is ever created.
|
|
Subsequent attempts to create a new instance will return the existing one.
|
|
|
|
Usage:
|
|
@singleton
|
|
class MySingletonClass:
|
|
def __init__(self):
|
|
# ... initialization ...
|
|
pass
|
|
|
|
Args:
|
|
cls: The class to be decorated.
|
|
|
|
Returns:
|
|
A wrapper function that handles instance creation.
|
|
"""
|
|
instance = [None]
|
|
|
|
def wrapper(*args, **kwargs):
|
|
if instance[0] is None:
|
|
instance[0] = cls(*args, **kwargs)
|
|
return instance[0]
|
|
|
|
return wrapper
|