try:
    result = task.get()
except TimeoutError:
    print('Task: %s took more than 5 seconds to complete' % task)
Asynchronous multiprocessing with a worker pool in Python: how to keep going after timeout?