It looks like you're trying to treat timeout differently. You should rescue TimeoutError and deal with it there instead.  Also, you should never print backtraces. Log them instead.