Python Script speed

I am running a Phyton script by a macro button like,

“_-RunPythonScript “D:\Dropbox\Software\Rhino7\Plugins\Gems.py”
Round
Enter”

and this process is taking about 3 seconds to start. Is that normal?
Ideally I’d like to have no delay at all.

Thank you
Murat

Does the delay occur only on the first run or on every run? If it’s on the first run in a session, Python needs to load on-demand before the script runs and that takes a couple of seconds. After that execution should normally be fast.

If the delay is on every run, then it’s the plug-ins fault. Hard to know why, it might be loading a library or something… have to ask the creator of the plug in.

First run is around 3 seconds, following runs are about a second.

The first runs sounds about right for having to load Python. For the rest, I do not know what it is loading/doing for that one second, you would have to ask the plug-in maker. “Normal” Python scripts execute instantly here once python is loaded.

To make the first run faster, I force Python to load on Rhino startup. To do this, I use the following script:

LoadPython.py (142 Bytes)

To make it run at every startup, first save the script somewhere and then make a Rhino alias with the full path to it. I named the alias “LoadPython”, but you can name it anything you want. Then in Rhino Options>General, put your alias in the box “Run these commands every time Rhino starts”:

When Rhino starts, it calls the alias which runs the script and it will load the main Python components. Thereafter, even the first time you run a script with a button, it will run instantly.

If a script uses Grasshopper components, it also takes awhile to load those the first time and they are not part of the normal Python startup, so I use the following to load Python with the Grasshopper components at startup:

LoadPythonGH.py (191 Bytes)

3 Likes

Yep that’s normal. I’ve not profiled it, but even outside of Rhino, IronPython is much slower on initial start up than CPython, which doesn’t require .Net.

1 Like

Hello,
Yes this is normal and @Helvetosaur’s solution works well to speed it up. Also if the script itself is slow the then there may be ways to speed it up.

1 Like

Thank you. That seems to work and resolved the initial 3sec delay.

Murat