summaryrefslogtreecommitdiff
path: root/thread_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'thread_utils.py')
-rw-r--r--thread_utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/thread_utils.py b/thread_utils.py
new file mode 100644
index 0000000..ec13c6f
--- /dev/null
+++ b/thread_utils.py
@@ -0,0 +1,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 \ No newline at end of file