libevent + multiprocessing

なんか以外にイイ組み合わせ?

import socket
import traceback
import event
import time

from multiprocessing import Process

host = ''
port = 12345

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((host, port))

def time_thread(sock, packet, address):
  sock.sendto(packet, address)
  time.sleep(5)
  print "Got data from", address, packet

def handle_read(ev, sock, entype, args):
  try:
    packet, address = sock.recvfrom(4096)
    Process(target=time_thread, args=(sock, packet, address)).start()
  except (KeyboardInterrupt, SystemExit):
    raise
  except:
    traceback.print_exc()

if __name__ == '__main__':
  event.init()
  event.event(handle_read, handle=sock, evtype=event.EV_READ | event.EV_PERSIST).add()
  event.dispatch()