Subtle issue with how KLayout runs Pcell scripts and possible bug


I just started to write my own script for a Pcell for KLayout. If I have a bug that is not present when I run the script in the IDE, but causes the script to crash when run when adding the Pcell to a layout, KLayout crashes in a bad way. I get an error message that I cannot get rid. The pointer turns to a red crossed circle and I cannot click anything in KLayout:

Please let me know if I can provide any additional information to resolve the issue. I run on Windows 10 with the latest KLayour binary downloaded from

One subtle issue that can cause the above situation is if I try to access a file in the current working directory from my script. But the current working directory is different in the two contexts, and thus if the file is missing in one of those directories, I get the above error.


  • Please paste your code. This is a Python exception and something is wrong inside your PCell code. You're trying to access an index in a dictionary which does not exist. I can't tell more without having your code.

    I can reproduce the problem when I put something stupid like

        d = { 1: "b" }

    but I don't see the program hanging. At least not on Linux. My version is 0.27.4.

    One advice is to turn off the debugger here:

    This will prevent the debugger from showing the exception and enter an UI lock. You can do debugging then by putting print statements into your code and check what is happening.


  • Ah, now I see. I was running the debugger, and it caught the exception. I was not aware of that. If I run my script with some error (e.g. like yours above) with the debugger on the above dialogue appears. If I run it from the IDE the dialogue appears and I can click the buttons and all is well. However, if the script is run due to a redraw when changing a parameter of the PCell, then the same dialogue appears but then the mouse pointer turns to a red circle and I cannot click anything.

    I am running KLayout 0.27.3 on Windows 10. So, this will happen if any exception is caught by the debugger it seems.

  • It looks like Linux behaves differently here. I'll try to reproduce that on Windows.


Sign In or Register to comment.