Jump to content

execute in main thread with results


Milan

Recommended Posts

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

Link to comment
Share on other sites

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 by Stalkerx777
Link to comment
Share on other sites

  • 2 weeks later...

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()
  • Like 2
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...