The simplest solution to your problem is to just have your heavy function 
create and update a progress bar as it runs.

In your sample code, there really won’t be a way for your function to update a 
progress bar as it runs unless you pass it in as another argument. In that 
case, you would still have to make the updates from within your heavy function 
anyway, so why not just create and delete the progress bar in it as well and 
save yourself some trouble?

However, as a sort of generic example of your question about passing args 
through one function to another, you can take in args and kwargs for a child 
function as a tuple and dict respectively, and then unpack them onto the child 
function:

def heavyFunc(path, anotherArg, someOtherKwarg=False):
    pass

def progressBar(func, funcArgs, funcKwargs):
    func(*funcArgs, **funcKwargs)

threading.Thread(None,progressBar, args=(heavyFunc, ('/some/path', 42), 
{'someOtherKwarg': True})).start()


Also, make sure you’re using calls to nuke.executeInMainThread in your heavy 
function where appropriate.

Hope this makes sense.

-Nathan



From: Lucien FOSTIER 
Sent: Friday, September 07, 2012 6:29 AM
To: [email protected] 
Subject: [Nuke-python] thread and progress bar

Hi fellow TD, 

Im trying to create a progress bar for my lengthy process.

I had the hope I could make things modular by having a function creating the 
progress bar and keep my lengthy process in other functions.

But I'm reaching a dead end here cause I need to pass argument to my heavy 
function and the thread object does provide way to pass argument but apparently 
only to the target function that's to say the function creating the progress 
bar itself.

So anyone knows a way to pass arguments to my function being itself an argument 
to the function creating the progress bar.

Im not sure Im very clear here so let me paste a bit of code:

def heavyFunc(path):
    pass

def progressBar(func):

   func()

threading.Thread(None,progressBar,args=(heavyFunc,) ).start()

so Id like to include the path argument in that last line, somewhere...but 
where?

Hope someone can help! :)

Or if someone have another way of thinking that would solve the problem?

Cheers

-- 
lucien FOSTIER 



--------------------------------------------------------------------------------
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to