KLayout run-time longer than external editor

edited October 2016 in Python scripting
Hello all,

I was curious if there is any known causes for slow run-time in the KLayout Python editor. I have some code that involves solving a system of equations numerically using numpy. When I run it in KLayout it takes 4 times as long as when I run it in an external python editor (I'm using Canopy). I'm using the exact same code in both cases so I'm confused as to why it is taking so much longer in KLayout.

Any ideas?

Thanks,
Nathan

Comments

  • edited October 2016

    Hi Nathan,

    while the editor is opened, the debugger is active. This slows down execution, because the debugger will hook itself into the interpreter. This will enable interacting with the execution of the code, but slow down each Python operation. Maybe performance can be improved here, but in general this feature is not without impact on performance.

    You can disable the debugger (deselect the small bug icon atop) to get speed up to normal. But since your code executes within the main thread, running a Python application this way will basically lock out the user interface event loop and make the application freeze until your procedure has finished.

    The debugger is intended to develop code that finally runs within the application outside the editor - for example triggered from some event, some menu function or within a PCell. Code executed this way won't run under control of the debugger and execute at normal speed. You can also create Python scripts and run them in KLayout's batch mode without a user interface. Such scripts will need to implement the whole setup - loading a layout, running a function on it, saving the results etc. Such batch script code is also executed at full speed.

    Matthias

  • edited November -1
    Hi Matthias,

    Thanks for the answer! That makes perfect sense and in hindsight seems very obvious.

    Nathan
  • edited November -1

    Hi Nathan,

    Python allows for multi-threading. It seems that the libraries are already present for this (on the MacOS version).

    https://www.tutorialspoint.com/python/python_multithreading.htm

    Perhaps your complicated scripts could be sped up this way?

Sign In or Register to comment.