Receive Remote Rhino Code in Subthread and run it Mainthread

socket_server.py (903 Bytes)
I have wrote a simple script to recieve Rhino code generated by LLM and excute.
However, this script runs in main thread which blocks the Rhino UI, I have to use “break” to stop it after the Rhino Code is recieved.

I want to run the socket in the subthread, and let the subthread send the Rhino code to mainthread to excute. If it is possible, I also want to send the cli stdout and stderror back to the LLM after the Rhino code is excuted.

Could someone tell me what knowledge should I learn for my plan? It would be the best if you could give me the specific documentation.

Thanks

You need to learn:

  • multi-thread programming
  • mechanisms to communicate between different threads
  • keywords: lock, semaphore, mutex, thread safety, race condition

Remember that accessing the Rhino document (RhinoDoc) is not thread-safe. You should make changes to the document only ever on the main thread, and pretty much also do the reading on the main thread.

Wouldn’t this work a lot better running the code from the LLM using Rhino Inside from Python (headless Rhino from Python) or RhinoCompute (Rhino on a server), instead of trying to automate Rhino, from a different thread within the same Rhino instance?

We want a visual modeling result

Don’t run Rhino headless then, just run it from the command line and you’ll see the GUI as normal.