15cc5d22f0
Libsaria events now support starting specific callback functions in a background thread. This replaces starting a specific event in the background. I have a library tab that is added to the main window through use of the ocarina.add_tab function. I have new tests for walking the tree and running multiple threads with locks.
42 lines
688 B
Python
42 lines
688 B
Python
# Bryan Schumaker (8/19/2010)
|
|
|
|
import threading
|
|
Thread = threading.Thread
|
|
Mutex = threading.Lock
|
|
|
|
|
|
mutex_mutex = Mutex()
|
|
mutexes = dict()
|
|
|
|
|
|
class BG_Thread(Thread):
|
|
def __init__(self, func, *args):
|
|
Thread.__init__(self)
|
|
self.func = func
|
|
self.args = args
|
|
def run(self):
|
|
self.func(*self.args)
|
|
|
|
|
|
def background(func, *args):
|
|
try:
|
|
th = BG_Thread(func, *args)
|
|
th.start()
|
|
return th
|
|
except Exception,e:
|
|
print e
|
|
return None
|
|
|
|
|
|
def get_mutex(lock_name):
|
|
global mutexes
|
|
global Mutex
|
|
global mutex_mutex
|
|
mutex_mutex.acquire()
|
|
lock = mutexes.get(lock_name, None)
|
|
if lock == None:
|
|
lock = Mutex()
|
|
mutexes[lock_name] = lock
|
|
mutex_mutex.release()
|
|
return lock
|