20 lines
530 B
Python
20 lines
530 B
Python
import functools
|
|
from threading import Thread
|
|
|
|
def threaded(fn):
|
|
"""Decorator to automatically launch a function in a thread"""
|
|
@functools.wraps(fn)
|
|
def wrapper(*args, **kwargs):
|
|
thread = Thread(target=fn, args=args, kwargs=kwargs)
|
|
thread.start()
|
|
return thread
|
|
return wrapper
|
|
|
|
def singleton(cls):
|
|
instances = {}
|
|
def getinstance(*args, **kwargs):
|
|
if cls not in instances:
|
|
instances[cls] = cls(*args, **kwargs)
|
|
return instances[cls]
|
|
return getinstance
|