Milan Posted April 21, 2015 Share Posted April 21, 2015 Hey guys. I'm trying to find equivalent to maya's and nuke's executeInMainThreadWithResult helper function. The point is that I'd like to spawn a child thread using python in houdini and have it communicate back to the main thread. Ideally waiting for response. Has anyone tried that, and if so how successful were you? The best explanation of what I'll need to do is having a look at these 2 pages of nuke and maya docs, which explain it very clearly. http://docs.thefoundry.co.uk/nuke/63/pythondevguide/threading.html http://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/Maya/files/Python-Python-and-threading-htm.html I'm planning to start ingegrating pyblish (http://www.pyblish.com/) into houdini and this would make it fairly straightforward. Cheers Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted April 22, 2015 Share Posted April 22, 2015 (edited) I think you could use this method to add callback, which will be executed in main thread. import threading import hou def callback(): print 'In callback' worker() hou.ui.removeEventLoopCallback(callback) print "I'm done with it" def worker(): print "I'm doing something" class T(threading.Thread): def run(self): hou.ui.addEventLoopCallback(callback) T().start() Edited April 22, 2015 by Stalkerx777 Quote Link to comment Share on other sites More sharing options...
Milan Posted May 5, 2015 Author Share Posted May 5, 2015 Hmm I though so too, but it seem to be running constantly (I assume on every ui update). And I'm unable to stop it. Quote Link to comment Share on other sites More sharing options...
edward Posted May 9, 2015 Share Posted May 9, 2015 I must be missing something. Why do you need to execute it in the main thread? ie. why not just spawn a python thread do do you work and then call join() on it to wait for it to finish. Quote Link to comment Share on other sites More sharing options...
Milan Posted May 12, 2015 Author Share Posted May 12, 2015 We were integrating http://www.pyblish.com into houdini. It runs outside of houdini as endpoint service. This approach was used in maya and nuke, so we were wondering if it was possible to plug it into houdini in the same fashion to keep the same structure of the integration. I was trying to just use join(), however it kept on freezing my houdini (which most likely means I was doing something very wrong ) Anyways we got it working thanks to SESI support and pyblish for houdini will be out and usable as soon as the code get's a tiny bit of cleanup and when it get's integrated into the main package. Turns out houdini has exactly what we were looking for import hdefereval hdefereval.executeInMainThreadWithResult(houdini_command) The way we got it working is this. import hou import hdefereval import threading def houdini_command(): hou.node('/obj').createNode('geo') def worker(): n = 0 while n < 5: hdefereval.executeInMainThreadWithResult(houdini_command) n += 1 thread = threading.Thread(target=worker) thread.daemon = True thread.start() and this was a try with join() which I gave up on. import hou import hdefereval import threading def worker(): n = 0 while n < 10: houdini_command() n += 1 thread = threading.Thread(target=worker) thread.daemon = True thread.start() thread.join() 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.