Zend certified PHP/Magento developer

How to skip a function if it takes longer than x time (socket) [migrated]

The code:

import socket
HOST = ''
PORT = 1000
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((HOST,PORT))
server.listen()
server.accept()   #the script stops here waiting for a connection to the server, but I want it
                  # to keep running the lines below if no one connects in the next 5 seconds.

print('running...')    

‘runnung’ is not printed because no one connected, but I want it to be printed anyway, after 5 sec waiting a connection