Hi Cython team, I encountered SIGSEGV or Illegal instruction errors upon return None from exception handler within another exception handler.
Here is the reproductive sample codes in three py files.
# sub.py ===
from datetime import datetime, date
def func():
text = "2020-10-23" # date format intentionally unmatched with arg in strptime()
try:
s = datetime.strptime(text, "%d%b%Y")
return s
except ValueError as err:
try:
print("Error1", err)
s = datetime.strptime(text, "%d%b%Y")
return s
except ValueError as err:
print("Error2", err)
return None # <------ this is where the code breaks
# main.py ===
import sub
print("main:", sub.func())
# setup.py ===
from distutils.core import setup
from Cython.Build import cythonize
setup(name="sub.app", ext_modules=cythonize("sub.py", language_level = "3"))
before I use python setup.py build_ext --inplace, I use python main.py and got:
Error1 time data '2020-10-23' does not match format '%d%b%Y'
Error2 time data '2020-10-23' does not match format '%d%b%Y'
main: None # <---- 'None' is returned as expected
but, after Cython, I use python main.py again and got:
Error1 time data '2020-10-23' does not match format '%d%b%Y'
Error2 time data '2020-10-23' does not match format '%d%b%Y'
Illegal instruction: 4 # <--- code is broken before print() in main.py is executed
Here is what I did to overcome this:
# sub.py ===
from datetime import datetime, date
def func():
s = None # <---- add this line first
text = "2020-10-23"
try:
s = datetime.strptime(text, "%d%b%Y")
return s
except ValueError as err:
try:
print("Error1", err)
s = datetime.strptime(text, "%d%b%Y")
return s
except ValueError as err:
print("Error2", err)
# return None # <--- do not return None from the exception handler
return s # instead, return from main body of the function
In my project codes (sorry I cannot copy here), the program is also broken, except SIGSERV received at the same location. In the code, func() is actually a @classmethod function of a class.
Version: Python 3.7.7 (anaconda), Cython 0.29.15.
Hi Cython team, I encountered
SIGSEGVorIllegal instructionerrors uponreturn Nonefrom exception handler within another exception handler.Here is the reproductive sample codes in three py files.
before I use
python setup.py build_ext --inplace, I usepython main.pyand got:but, after Cython, I use
python main.pyagain and got:Here is what I did to overcome this:
In my project codes (sorry I cannot copy here), the program is also broken, except SIGSERV received at the same location. In the code, func() is actually a
@classmethodfunction of a class.Version: Python 3.7.7 (anaconda), Cython 0.29.15.