"While Loop", can we make TOP listen and act

   209   4   1
User Avatar
Member
39 posts
Joined:
Offline
I'm looking for a way start a listening/interactive mode with tops.
Can I have a loop that polls a database mysql/sqlite or something for changes and then query something and be processing whatever path I get back from it?

Not sure where to start. I can do it in python outside of houdini, but I'd rather have it all running inside of a houdini session that is just listening to a database.

Not sure where to start, if at all possible. Any pointers, help file or tutorial would be great!

Thanks!
User Avatar
Member
39 posts
Joined:
Offline
Ok, so I have found a solution, which I think could be improved upon.
This setup keeps a heartbeat runnig for 30 seconds and each second you can generate new work_items. You can obviously change number of heartbeats and wait time. So this allows you to fetch live data form a database or folder for example and act accordingly. There's no logic for tracking what was processed, you need to build that yourself. But it's at least a way to keep houdini polling.

Now in the file, I have also 2 python generators which I think would be the proper solution, but can't get to work.
I'd love to know if there's anything better of more robust perhaps.

Hope it helps someone and if you have feedback please let me know!

Attachments:
PDG_while_loop_tests.hiplc (141.7 KB)

User Avatar
Staff
352 posts
Joined: May 2014
Offline
There isn't a built in way to do that right now, but we are planning to add support for file system watching/triggers in the future. The same functionality could be generalized to other external resources.

One option that exists now is to use an experimental feature that's not available from the UI, but can be used from the Python Shell or a button callback script. You can cook a TOP graph with “continuous cooking” enabled – when the network finishes it will automatically recook itself after a time out period. This can still be interrupted by canceling with ESC or from the Tasks menu. You can use that in combination with a Python Processor node that has custom work item Regeneration logic. The onRegenerateStatic hook will run at the beginning of each cook, and you can use it to delete, add or dirty existing work items.

The actual cook options are described here: https://www.sidefx.com/docs/houdini/tops/pdg/CookOptions.html [www.sidefx.com]

To use that, you'd need to manually cook the TOP graph using something like the following:

import pdg

top_node = hou.node('/obj/topnet1/')
pdg_context = top_node.getPDGGraphContext()
top_node.executeGraph(True, False, True)
options = pdg.CookOptions()
options.autoRecook = True
options.autoRecookInterval = 100
options.cookType = pdg.cookType.Full
options.blocking = False
pdg_context._cook(options)

You can put in a button callback for example, to trigger the cook. Once a cook completes PDG will recook the output node automatically in a loop, until the graph is canceled. When used with a node like the File Pattern, for example, changes to the file system will cause the work items to be dirtied/updated on the next cook.
Edited by tpetrick - July 27, 2020 15:34:34
User Avatar
Member
39 posts
Joined:
Offline
Yes, this is exactly it!!
Thanks so much for this, it's so much better now, python processor recook/regenerate works great!

Really great stuff, can't wait for this to be available as nodes. It would be great to be able to have portions of the flow doing polling while other parts are collecting and processing for example.
But that's icing on the cake, this helps a lot.

Cheers!
User Avatar
Member
39 posts
Joined:
Offline
As an addendum, it might be worth mentioning that any python operation that is calling file operations like process.Popen/os.call etc is best called in a python server and a Command Sent node. After many calls to it in a normal python node it locks up the UI and eventually stops processing all together. Not sure wby, but I think in the second run some thread/hooks are not cleaned up properly otherwise. I'm seeing this issue
  • Quick Links