def request(host, port, child_num, con_num, bytes):
    # spawn child_num children processes
    for cnum in range(child_num):

        pid = os.fork()
        if pid == 0: # child

            for i in range(con_num):
                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                sock.connect((host, port))
                sock.sendall(str(bytes))

                data = sock.recv(bytes)
                if len(data) != bytes:
                    raise Exception('Server returned only %d bytes' % len(data))

                sock.close() # TIME_WAIT state on the client

            print 'Child %d is done' % cnum
            os._exit(0)

    # wait for all children to finish
    while True:
        try:
            pid, status = os.wait()
        except __HOLE__ as e:
            if e.errno == errno.ECHILD:
                break
            else:
                raise

        if pid == 0:
            break
dataset/ETHPy150Open rspivak/csdesign/client.py/request