Threading is unnecessary for this - you can still use ProgressTask usefully while blocking the main thread:
def createBlurNodes(): t = nuke.ProgressTask("Creating Blurs") num = 1000 for i in range(num): if t.isCancelled(): raise RuntimeError("Cancelled") nuke.createNode('Blur', '', False) t.setProgress(int(100 * ((i-1) / num))) t.setMessage("Created %d of %d" % (i+1, num)) createBlurNodes() This way you still block the UI, which is probably desirable (otherwise what happens if, say, the user arbitrarily deletes one of your TimeOffset nodes?), but the ProgressTask means the UI still redraws, you can click the cancel button and so on. On 28/07/14 22:25, Bram Buddingh wrote: > Hi everybody, > > I am working on a python script that creates more than 25 read nodes with > approximately 30 timeOffset nodes connected to each of them. So I end up with > a script containing something like 1000 nodes. This could be extended later, > depending on the needs. > > This is quite compute intensive to run. The main nuke thread/window freezes > and you don’t know how long you have to wait until it’s finished. I am trying > to put this in a separate thread with a status bar. The problem is that the > threaded way is even slower than without putting it in a separate thread. To > make it a bit clear, I wrote some python lines to demonstrate what I am > trying to do: > > > -------------------------------------------------------------------------------------------- > import threading > > ### option 1: even slower than option 2 ### > def createBlurNodes(): > task = nuke.ProgressTask("Create") > task.setMessage("Creating blur nodes") > > for i in range(1000): > nuke.executeInMainThreadWithResult(nuke.createNode, args = ('Blur', > '', False)) > task.setProgress(i/10) > > threading.Thread(None, createBlurNodes).start() > > > ### option 2: slow and I don't have visible feedback about the estimated > calculation time. Plus nuke is freezing for a couple of seconds, depending on > your machine specs. ### > for i in range(1000): > nuke.createNode('Blur', '', False) > > -------------------------------------------------------------------------------------------- > > Maybe it’s slow because nuke.createNode is always running in the main thread? > > Is this the correct way, or is there a better way to script this? > Thanks for the help in advance! > > Bram Buddingh_______________________________________________ > Nuke-python mailing list > Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python > -- ben dickson 2D TD | ben.dick...@rsp.com.au rising sun pictures | www.rsp.com.au _______________________________________________ Nuke-python mailing list Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python