def disconnect(host):
    host = host or fabric.api.env.host_string
if host and host in fabric.state.connections:
    fabric.state.connections[host].get_transport().close()
Disconnecting from host with Python Fabric when using the API