summaryrefslogtreecommitdiff
path: root/thread_utils.py
blob: ec13c6f0397e01361bdb26a795626c37b3eee268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import threading
"""
Quick implementation of a @synchronized and @asynchronized decorators
"""

#To be replaced by bukkit scheduler.
"""
def sync(lock=None):
    def decorator(wrapped):
        def wrapper(*args, **kwargs):
            with lock:
                return wrapped(*args, **kwargs)
        return wrapper
    return decorator
"""

def async(daemon = True):
    def decorator(function):
        def wrapper(*args,**kwargs):
            thread = threading.Thread(target=function,args=args,kwargs=kwargs)
            thread.daemon = daemon
            thread.start()
        return wrapper
    return decorator