added a timeout

Added a simple timeout mechanism according to http://pguides.net/python-tutorial/python-timeout-a-function/