PythonScript ExecuteFile Command Throw an error


(Jessen Ch) #1

Hello everyone,

My first post here:)

I have encounter a problem when using ExecuteFile method in PythonScript class.

I am developing a rhino plugin in C#. And I am using another thread to listen to messages from other app and then in Rhino run some python code from local machine.

I have narrow down the buggy script as below:

Which throws an exception when debugging the code.

The exception detail is like this:

Anyone has a solution? Thanks in advance!

Also anyone who has ever used pythonscript class could you share your experience of it?

Thanks!
Rhino rocks


(Jessen Ch) #2

By the way, if I replace ExecuteFile method with ExecuteScript method, there is no such an error.

But I am willing to import other python files in my python code so ExecuteScript method does not work here.


(Dale Fugier) #5

Hi @jessen.ch,

What if you don’t run the script from a thread? Rhino is not thread-safe. So this very well can be the problem.

– Dale


(Jessen Ch) #6

Hi @dale,

Many thanks for your reply.

The reason I use thread is that I am running a TCP server to listen to messages and once received a command then run a python script.

If I run the TCP server from the main thread, the server would hang the whole Rhino application, since the TCP server runs with while (true) block.

Maybe I am doing it wrong. Is there an alternative to run the server in the background? Or how can I force the main thread to run ExecuteFile command?


(Jessen Ch) #7

Thanks to this post RunScript in a thread by @jstevenson72, I have figured out how to make it!