From 9525cfd1cd8a7acadc67da3975048ad49c49d7f3 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 11 Dec 2023 23:55:57 +0100 Subject: [PATCH 1/2] Fixed #1565 (quit() raises an error in KLayout Python Console) --- src/pya/pya/pyaUtils.cc | 4 +++- testdata/klayout_main/main.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pya/pya/pyaUtils.cc b/src/pya/pya/pyaUtils.cc index 0bded8e92..65f1d7678 100644 --- a/src/pya/pya/pyaUtils.cc +++ b/src/pya/pya/pyaUtils.cc @@ -119,7 +119,9 @@ void check_error () int status = 0; if (exc_value) { tl::Variant st = python2c (exc_value.get ()); - status = st.to_int (); + if (st.can_convert_to_int ()) { + status = st.to_int (); + } } throw tl::ExitException (status); diff --git a/testdata/klayout_main/main.rb b/testdata/klayout_main/main.rb index f867f4339..7b452d376 100644 --- a/testdata/klayout_main/main.rb +++ b/testdata/klayout_main/main.rb @@ -201,6 +201,14 @@ class KLayoutMain_TestClass < TestBase out = `#{self.klayout_bin} -z -r #{File.join(File.dirname(__FILE__), "test12.rb")} 2>&1` assert_equal(out, "Before exit()\n") + # sys.exit(0) - Python + out = `#{self.klayout_bin} -z -r #{File.join(File.dirname(__FILE__), "test12s.py")} 2>&1` + assert_equal(out, "Before exit()\n") + + # quit() - Python (issue #1565) + out = `#{self.klayout_bin} -z -r #{File.join(File.dirname(__FILE__), "test12q.py")} 2>&1` + assert_equal(out, "Before quit()\n") + end end From bbd7a9cd8a23b02f152a70b95af7a8c4e502cb81 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 11 Dec 2023 23:56:28 +0100 Subject: [PATCH 2/2] Added missing files --- testdata/klayout_main/test12q.py | 4 ++++ testdata/klayout_main/test12s.py | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 testdata/klayout_main/test12q.py create mode 100644 testdata/klayout_main/test12s.py diff --git a/testdata/klayout_main/test12q.py b/testdata/klayout_main/test12q.py new file mode 100644 index 000000000..6f829f98b --- /dev/null +++ b/testdata/klayout_main/test12q.py @@ -0,0 +1,4 @@ + +print("Before quit()") +quit() + diff --git a/testdata/klayout_main/test12s.py b/testdata/klayout_main/test12s.py new file mode 100644 index 000000000..9d007aca5 --- /dev/null +++ b/testdata/klayout_main/test12s.py @@ -0,0 +1,6 @@ + +import sys + +print("Before exit()") +sys.exit(1) +