Threading in python #7440
Unanswered
lee-deraud
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
Hi @lee-deraud! For Open3D GUI operations, you're dealing with thread-safety constraints similar to most GUI frameworks. Here's what you need to know: Thread-Safe ApproachInstead of trying to find which functions are thread-safe, I'd recommend using Open3D's built-in threading model: import open3d as o3d
def gui_update_callback():
# Your GUI updates here
# This runs safely in the main thread
return True # Return False to stop
# In your main thread
app = o3d.visualization.gui.Application.instance
app.post_to_main_thread(window, gui_update_callback)General Pattern for Threaded Operationsfrom threading import Thread
import open3d as o3d
class MyVisualizer:
def __init__(self):
self.app = o3d.visualization.gui.Application.instance
self.window = self.app.create_window("My Window", 1024, 768)
def background_work(self):
# Heavy computation in background thread
result = self.process_point_cloud()
# Post result back to main thread for GUI update
self.app.post_to_main_thread(
self.window,
lambda: self.update_gui(result)
)
def update_gui(self, result):
# All GUI operations here are safe
passKey Guidelines
This pattern is more reliable than trying to determine which specific functions are thread-safe, as it can change between versions. Hope this helps! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Can someone point me to anything in the documentation showing which functions do not execute in the main thread?
There are several mentions in the docs/examples of the restriction on updating the GUI from non-min threads, but most specific examples were deliberately contrived to demonstrate the post_to_main_thread() function. Only the callback designated by render_to_depth_image(() is explicitly called out as executing in its own thread, and I discovered (the hard way) the callbacks from file dialogs also seem to do so.
But I'd love to find some more elegant way to discover any others than by crashing the GUI.
Beta Was this translation helpful? Give feedback.
All reactions