

def server(host, port, func):
    'A coroutine that runs a network server. Host and port specify the\n    listening address. func should be a coroutine that takes a single\n    parameter, a Connection object. The coroutine is invoked for every\n    incoming connection on the listening socket.\n    '

    def handler(conn):
        try:
            (yield func(conn))
        finally:
            conn.close()
    listener = Listener(host, port)
    try:
        while True:
            conn = (yield listener.accept())
            (yield spawn(handler(conn)))
    except KeyboardInterrupt:
        pass
    finally:
        listener.close()

dataset/ETHPy150Open beetbox/beets/beets/util/bluelet.py server/original