import os
import time
import socket
import threading


def child():
    # give it enough time to get in to accept()
    time.sleep(1)
    print "trying to exit..."
    os._exit(3)


s = socket.socket()
s.bind(('0.0.0.0', 13579))
s.listen(5)
s.settimeout(3)

threading.Thread(target=child).start()

while 1:
    print "in accept"
    try:
        r = s.accept()
    except Exception, e:
        print "accept err", e
    else:
        print "out accept", r


