ScriptEditor - Reset

@eirannejad

Is there a way to really reset python3 in the script editor?

Reason:
If we change code in python vscode, we need to close rhino. After opening again it works.
Whereas Tools->Reset Python 3 does not do any change.

Any non standard solution would work for us too, to avoid restart of rhino.

I have the same problem with my C++ DLL in Visual Studio 2022. Once Rhino starts up and uses the DLL, I cannot recompile the DLL without restarting Rhino. Rhino puts a lock on the DLL file and will not release it without a restart. The lock prevents the build process from completing in VS as the last step of writing out the DLL is blocked.

I have endured this problem for the last 4 years. So if there is some way to release the file lock in Rhino without a restart, it would be much appreciated.

Regards,
Terry.

C++ and .NET is I guess another thing.

But for Python there is an editor that I guess could be restarted. If it is not in memory…

@Petras1 We have made improvements in Rhino 8.6 for better python reloading. You can:

  • Use Tools → Reset Python Engine from the editor menus
  • Use -ResetEngine option with RunPythonScript command
  • Specify # flag: python.reloadEngine in your script to always reload the engine before running the script (both python 3 and 2)

Does it mean that we need to wait until 8.6 ?

Because there is 8.5 service candidate only.
And currently Tools → Reset Python Engine has no effect.
I will try also the flag option. Issue is as always: development in vscode and running code in rhino.

8.6 RC is coming out next Tuesday so it’d be great if you can try that and let me know if it works

2 Likes

Looking forward to it:)

Any hope for a command to get Rhino to release its lock on the DLL file so that a new DLL can be written out by VS without restarting Rhino?

That’s Windows / dotnet runtime behaviour. Once a dll is loaded the file is locked and can not be replaced or deleted. Unless the assembly is loaded from pure binary data which causes a bunch of other problems namely Assembly.Location would return empty.

@eirannejad We tried Reset Python Engine, it does not work on the latest Rhino8

All the editable pip install do not work anymore, that previously worked before.
We need to install all python packages again.

@Petras_Vestartas It would be great if you can share instructions on how to repeat this problem. There has been no major change to the python runtime layout or pip version. When rhino installs a new python environment all the existing packages under site-envs are cleared so it is important to have package references inside scripts. That ensures they are reinstalled automatically.

Not sure if this is helping but I really have no idea what is your setup on your machine, what kind of libraries are you trying to reload, or what is your editable pip install package setup.

It is not related to new rhino update.

The wish is: I change code in VSCode and after I reset python engine of rhino I can run the code. Instead I need to restart rhino. I thought reset command would allow to use newly updated code without rhino restart.

Configuration: I have a conda environment with a simple compas package that is under development and pip editable install to rhino python script editor. Th example was compas_wood, no c++ code change only python.

Ok lets start testing. Here is one. Does this workflow not work on your machine?

2 Likes

Works! Amazing! :rocket:

Another Question:

I have a python package that wraps C++ code. In Visual Studio terminal, I can see printed messages that are printed in C++.

Do you have any clue why these messages are not printed in Rhino ScriptEditor Terminal?
What is happening here is in C++ python binding printf() method called. It is super nice way to debug…

printf and other similar functions in C++ write to a known file handler named stdout (lets call this native stdout) that is automatically opened for every process, running from terminal , by the OS. So when you run your python program from the terminal , the resulting python process is bound to a stdout and all the outputs are captured and printed to the terminal window.

In a UI app like Rhino, the output printed to native stdout is not captured since the app is not bound to a terminal. You can run the macOS Rhino from the terminal and see the native output printed to the terminal window (Run the Rhinoceros.app/Contents/MacOS/Rhinoceros directly and not using open command otherwise the output will not be captured. You have to use Start-Process -Wait -RedirectStandardOutput command in Windows powershell)

When running a script from script editor, a new stream is created to represent stdout and is bound to the sys.stdout so all outputs from python scripts an be captured. When running Rhino normally and not using the methods described above, all the messages printed to the native stdout are skipped.

This is nice, I wish I would have known this earlier. SuperCool now this will be my way of opening Rhino :slight_smile:

1 Like