That first paragraph was poorly-worded. What I meant to say is "nuke.executeInMainThreadWithResult is going to impose a performance hit on your sample code due to thread juggling, since each switch requires the running Python thread to grab the GIL."
-Nathan From: Nathan Rusch Sent: Monday, July 28, 2014 10:11 AM To: Nuke Python discussion Subject: Re: [Nuke-python] Running heavy code in separate thread withprogressbar No, it doesn't create a thread. However, nuke.executeInMainThreadWithResult is going to impose a performance hit, since your sample code is juggling threads, and each switch requires the running Python thread to grab the GIL. I think what Dan was getting at is that you should refactor your code so the callable you pass to executeInMainThread does its own looping internally, to cut down on thread switching in Python. Also, you should only use executeInMainThreadWithResult if you actually need the result from the main thread call; use executeInMainThread otherwise. Finally, make sure to create your nodes without control panels. This runs in a little over a second: def createBlurs(count, progressTask): for i in xrange(count): nuke.createNode('Blur', inpanel=False) progressTask.setProgress(i / 10) def threadCallable(): task = nuke.ProgressTask('Create') task.setMessage('Creating blur nodes') nuke.executeInMainThread(createBlurs, args=(1000, task)) threading.Thread(target=threadCallable).start() -Nathan From: Bram Buddingh Sent: Monday, July 28, 2014 8:40 AM To: Nuke Python discussion Subject: Re: [Nuke-python] Running heavy code in separate thread with progressbar Ah! It looks like that is working…haha. So, each time I run the code ‘nuke.executeInMainThreadWithResult’ Nuke is starting a thread? I thought it only executes a piece of code in the main thread and that you call a new threat with 'threading.Thread(None, ‘function').start()’. Thanks! Bram On Jul 28, 2014, at 4:19 PM, Dan Rosen wrote: Try the for loop inside the thread rather than a thread for each time it loops. Maybe? On Jul 28, 2014, at 5:57 AM, Bram Buddingh <b...@postoffice.nl> 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 _______________________________________________ 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 -------------------------------------------------------------------------------- _______________________________________________ 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 -------------------------------------------------------------------------------- _______________________________________________ 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
_______________________________________________ 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