Author: dmeyer
Date: Sat Mar 1 04:51:00 2008
New Revision: 3139
Log:
add synchronized decorator (does not work with a coroutine)
Modified:
trunk/base/NEWS
trunk/base/src/notifier/__init__.py
trunk/base/src/notifier/thread.py
Modified: trunk/base/NEWS
==============================================================================
--- trunk/base/NEWS (original)
+++ trunk/base/NEWS Sat Mar 1 04:51:00 2008
@@ -4,7 +4,7 @@
* Again some API changes for kaa.notifier. Please read
API_CHANGES.txt for details. The API should be stable now.
-
+* synchronized decorator
0.3.0, 2008-02-04
Modified: trunk/base/src/notifier/__init__.py
==============================================================================
--- trunk/base/src/notifier/__init__.py (original)
+++ trunk/base/src/notifier/__init__.py Sat Mar 1 04:51:00 2008
@@ -43,7 +43,7 @@
# Thread callbacks, helper functions and decorators
from thread import MainThreadCallback, NamedThreadCallback, ThreadCallback, \
- is_mainthread, threaded, MAINTHREAD
+ is_mainthread, threaded, MAINTHREAD, synchronized
# Timer classes and decorators
from timer import Timer, WeakTimer, OneShotTimer, WeakOneShotTimer, AtTimer, \
Modified: trunk/base/src/notifier/thread.py
==============================================================================
--- trunk/base/src/notifier/thread.py (original)
+++ trunk/base/src/notifier/thread.py Sat Mar 1 04:51:00 2008
@@ -48,7 +48,7 @@
__all__ = [ 'MainThreadCallback', 'ThreadCallback', 'is_mainthread',
'wakeup', 'set_as_mainthread', 'create_thread_notifier_pipe',
- 'threaded', 'MAINTHREAD' ]
+ 'threaded', 'MAINTHREAD', 'synchronized' ]
# python imports
import sys
@@ -129,6 +129,22 @@
return decorator
+def synchronized(lock=threading.Lock()):
+ """
+ Synchronization decorator. This decorator does not work
+ together with coroutines (yet).
+ """
+ def decorator(f):
+ def newFunction(*args, **kw):
+ lock.acquire()
+ try:
+ return f(*args, **kw)
+ finally:
+ lock.release()
+ return newFunction
+ return decorator
+
+
def is_mainthread():
"""
Return True if the caller is in the main thread right now.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog