Sorry, I forgot about this bug again and filed a new one.
This is clearly a bug in python itself. Not sure how we're triggering it yet. See bug 38300.
*** This bug has been marked as a duplicate of bug 38300 ***