In Houdini Python API, how could I delay the execution of a function for several seconds without blocking the main thread?
Something similar to time.sleep(), but non-blocking.
How to wait for X seconds without blocking main thread?
1893 3 0-
- raincole
- Member
- 692 posts
- Joined: Aug. 2019
- Online
-
- maximumsproductions
- Member
- 3 posts
- Joined: Aug. 2017
- Offline
Was about to ask somewhat adjacently similar question.
I was hoping to see example of moving a node in networkview live every X seconds. I've been unsuccessful in terms of performance and have a feeling I'm doing this quite wrong.
In any case for your question I'd maybe recommend looking at :
and/or threading threading.Timer (stopping that process mid call I'm unsure though)
I wish I could find anymore documentation about hdefereval or if anyone has any other tips as I'd love to figure out a way to essentially run a function x timestep with this like a live node graph update, it gives me inconsistent behavior on how long that process takes.
I was hoping to see example of moving a node in networkview live every X seconds. I've been unsuccessful in terms of performance and have a feeling I'm doing this quite wrong.
In any case for your question I'd maybe recommend looking at :
hdefereval.executeInMainThreadWithResult
I wish I could find anymore documentation about hdefereval or if anyone has any other tips as I'd love to figure out a way to essentially run a function x timestep with this like a live node graph update, it gives me inconsistent behavior on how long that process takes.
Edited by maximumsproductions - July 29, 2024 15:00:02
-
- raincole
- Member
- 692 posts
- Joined: Aug. 2019
- Online
-
- maximumsproductions
- Member
- 3 posts
- Joined: Aug. 2017
- Offline
Heya! Sorry I didn't provide example. So hopefully I am answering this and not wasting your time --- as for me I considering "blocking" the main thread where my houdini shell just freezes hah but maybe I don't understand correctly.
I'm not really satisfied with this approach, as I'd like to just use time.sleep() and thread only but if you try this, does this help your needs? :
I'm not really satisfied with this approach, as I'd like to just use time.sleep() and thread only but if you try this, does this help your needs? :
import hou import hdefereval import threading import time def run_cmd_now(): print("run cmd now") def run_cmd_later(): print("run cmd later") def thread_run_cmd(): hdefereval.executeInMainThreadWithResult(run_cmd_now) time.sleep(2) hdefereval.executeInMainThreadWithResult(run_cmd_later) time.sleep(2) print("done") thread = threading.Thread(target = thread_run_cmd) thread.daemon = True thread.start()
-
- Quick Links


