Package nuke :: Module executeInMain
[hide private]
[frames] | no frames]

Source Code for Module nuke.executeInMain

 1  # Functions for parallel threads to run stuff that can only be 
 2  # in the main Nuke thread. Formerly in nukescripts.utils 
 3   
 4  import threading 
 5  import types 
 6  import _nuke 
 7   
 8  __main_thread_lock = threading.Lock() 
 9  __main_thread_event = threading.Event() 
10   
11 -def executeInMainThreadWithResult(call, args = (), kwargs = {}):
12 """ Execute the callable 'call' with optional arguments 'args' and named arguments 'kwargs' i 13 n 14 Nuke's main thread and wait for the result to become available. """ 15 if type(args) != types.TupleType: 16 args = (args,) 17 __main_thread_lock.acquire() 18 _nuke.RunInMainThread.request(call, args, kwargs, __main_thread_event) 19 __main_thread_event.wait() 20 try: 21 r = _nuke.RunInMainThread.result() 22 finally: 23 __main_thread_event.clear() 24 __main_thread_lock.release() 25 return r
26
27 -def executeInMainThread(call, args = (), kwargs = {}):
28 """ Execute the callable 'call' with optional arguments 'args' and named arguments 'kwargs' i 29 n 30 Nuke's main thread and return immediately. """ 31 if type(args) != types.TupleType: 32 args = (args,) 33 __main_thread_lock.acquire() 34 _nuke.RunInMainThread.request(call, args, kwargs) 35 __main_thread_lock.release()
36