The (first) Python stack overflow occurs at:

(gdb) pybt
Traceback (most recent call first):
File "/home/haypo/issue14537/sympy/py3ksympy/sympy/core/expr.py", line 2531, in expand
from sympy.simplify.simplify import fraction
File "/home/haypo/issue14537/sympy/py3ksympy/sympy/core/cache.py", line 91, in wrapper
func_cache_it_cache[k] = r = func(*args, **kw_args)
File "/home/haypo/issue14537/sympy/py3ksympy/sympy/functions/elementary/hyperbolic.py", line 514, in as_real_imag
return (self.expand(deep, **hints), S.Zero)
File "/home/haypo/issue14537/sympy/py3ksympy/sympy/functions/elementary/hyperbolic.py", line 525, in _eval_expand_complex
re_part, im_part = self.as_real_imag(deep=deep, **hints)
File "/home/haypo/issue14537/sympy/py3ksympy/sympy/core/expr.py", line 2551, in expand
expr = func(deep=deep, **hints)
File "/home/haypo/issue14537/sympy/py3ksympy/sympy/core/cache.py", line 91, in wrapper
func_cache_it_cache[k] = r = func(*args, **kw_args)
File "/home/haypo/issue14537/sympy/py3ksympy/sympy/functions/elementary/hyperbolic.py", line 514, in as_real_imag
return (self.expand(deep, **hints), S.Zero)
File "/home/haypo/issue14537/sympy/py3ksympy/sympy/functions/elementary/hyperbolic.py", line 525, in _eval_expand_complex
(gdb) where
#0 _Py_CheckRecursiveCall (where=0x624f4b " in comparison") at Python/ceval.c:736
#1 0x0000000000419e6a in PyObject_RichCompare (v='sympy', w='sympy', op=2) at Objects/object.c:604
#2 0x0000000000419f2d in PyObject_RichCompareBool (v='sympy', w='sympy', op=2) at Objects/object.c:628
#3 0x00000000005e854e in lookdict (mp=0x7ffff1b3b1a8, key='sympy', hash=191038920480525830) at Objects/dictobject.c:341
#4 0x00000000005e99ca in PyDict_GetItem (op=
{'sympy.logic.inference': <module at remote 0x7fffeef80ba0>, ..., key='sympy') at Objects/dictobject.c:752
#5 0x00000000004f1510 in import_submodule (mod=None, subname='sympy', fullname='sympy') at Python/import.c:3313
#6 0x00000000004f064b in load_next (mod=None, altmod=None, inputname='sympy.simplify.simplify', p_outputname=0x7fffffe67e28, p_prefix=0x7fffffe67e20)
at Python/import.c:3150
#7 0x00000000004ef610 in import_module_level (name='sympy.simplify.simplify', globals=
{...}, locals=None, fromlist=('fraction',), level=0)
at Python/import.c:2843

Ok, now I see the problem: import_submodule() uses PyDict_GetItem() whereas PyDict_GetItem() *clears* the exception (!). It should use PyDict_GetItemWithError() instead. Try attached patch. The problem is a generic problem: PyDict_GetItem() should be replaced by PyDict_GetItemWithError() everywhere... But it would be nice to start with import.c :)
