1   
 2   
 3   
 4  import traceback 
 5  import threading 
 6  import types 
 7  import _nuke 
 8   
 9 -def executeInMainThreadWithResult( call, args = (), kwargs = {}): 
 10    """ Execute the callable 'call' with optional arguments 'args' and named arguments 'kwargs' in 
11        Nuke's main thread and wait for the result to become available. """ 
12    if type(args) != types.TupleType: 
13      args = (args,) 
14   
15    resultEvent = threading.Event() 
16    id = _nuke.RunInMainThread.request(call, args, kwargs, resultEvent ) 
17    resultEvent.wait() 
18    try: 
19      r = _nuke.RunInMainThread.result(id) 
20    except: 
21      traceback.print_exc() 
22      r = None 
23   
24    return r 
 25   
26 -def executeInMainThread(call, args = (), kwargs = {}): 
 27    """ Execute the callable 'call' with optional arguments 'args' and named arguments 'kwargs' i 
28  n Nuke's main thread and return immediately. """ 
29    if type(args) != types.TupleType: 
30      args = (args,) 
31    _nuke.RunInMainThread.request(call, args, kwargs) 
 32