Profiling python

Hi

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

import rhinoscriptsyntax as rs
import profile


def runner():
    for i in range(1):
        rs.AddPoint(i,i,i)

profile.run(runner())

Error:

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

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

Thanks
-Willem

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:
-Willem

Fijne einde van de week!