<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def main(reactor):
 """ Close all open streams and circuits in the Tor we connect to """

    control_ep = UNIXClientEndpoint(reactor, '/var/run/tor/control')
    tor = yield txtorcon.connect(reactor, control_ep)
    state = yield tor.create_state()
    print("Closing all circuits:")
    for circuit in list(state.circuits.values()):
        path = '->'.join(map(lambda r: r.id_hex, circuit.path))
        print("Circuit {} through {}".format(circuit.id, path))
        for stream in circuit.streams:
            print("  Stream {} to {}".format(stream.id, stream.target_host))
            yield stream.close()
            print("  closed")
        yield circuit.close()
        print("closed")
    yield tor.quit()