Profiling python


I’m investigating possible options to profile our pyhon scripts
My first attempt with resulted in an error message. Message: No module named __main__

import rhinoscriptsyntax as rs
import profile

def runner():
    for i in range(1):


Message: No module named __main__
line 436, in run, "C:\Program Files\Rhino 6\Plug-ins\IronPython\Lib\"
line 61, in run, "C:\Program Files\Rhino 6\Plug-ins\IronPython\Lib\"
line 9, in <module>, "C:\Users\Willem\Desktop\"

Has anyone experience profiling python in Rhino and like to share your experience?
@stevebaer would you be able to provide some insight in this?


I believe there is no __main__ module because it is running through embedded Python

__main__ module

The profile module documentation says it will execute exec(command, __main__.__dict__, __main__.__dict__), so maybe you can just create a variable named __main__ that is an instance of a class that provides an empty dictionary in the member __dict__. 26.4. The Python Profilers — Python 2.7.18 documentation

Hi Nathan,

Thanks for the quick reply!
We’ll see if that will get the profiler working.

Dankjewel en fijn weekend :wink:

Fijne einde van de week!