title: paramiko/ Socket closes after returning console object from function
body: <p>I try to return socket object from function, but  after <code>return</code> socket immediatly closes. Any help is greatly appreciated :) Thanks</p>
  
  <pre><code>def get_connection(ip, log, paswd):
      ssh = paramiko.SSHClient()
      ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
      ssh.connect(ip, username=log, password=paswd, timeout=100)
      console = ssh.invoke_shell()
      print(console)
      return console
  
  
  def get_version(console, host):
      promt = console.recv(1000)
      if '&gt;' in str(promt):
          console.send('enable\n')
          console.send('P@ssw0rd\n')
      console.send('terminal length 0\n')
      console.send('show version\n')
      time.sleep(2)
      out = console.recv(5000).decode('utf-8')
      system_version_finder = re.search('#show version\r\n(.+)', out)
      if system_version_finder:
          system_version = system_version_finder.group(1)
      else:
          system_version = 'Unknown'
      print(host + '\s' + system_version)
  
  
  def upload_config(console, file_path):
      console.send('configure terminal\n')
      with open(file_path, 'r') as config_file:
          for line in config_file:
              console.send(line)
  
  for host in options.ip_address_list:
      console = get_connection(host, options.login, options.password)
      print(console)
      get_version(console, host)
      if options.conf_file_path:
          upload_config(console, options.conf_file_path)
  </code></pre>
  
  <p>This is output of script:</p>
  
  <pre><code>&lt;paramiko.Channel 0 (open) window=1024 -&gt; &lt;paramiko.Transport at 0x34f5e10 (cipher aes128-cbc, 128 bits) (active; 1 open channel(s))&gt;&gt;
  &lt;paramiko.Channel 0 (closed) -&gt; &lt;paramiko.Transport at 0x34f5e10 (unconnected)&gt;&gt;
  Traceback (most recent call last):
    File "llearn.py", line 65, in &lt;module&gt;
      get_version(console, host)
    File "llearn.py", line 32, in get_version
      console.send('terminal length 0\n')
    File "C:\Program Files (x86)\Python\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\channel.py", line 698, in send
    File "C:\Program Files (x86)\Python\lib\site-packages\paramiko-1.16.0-py3.4.egg\paramiko\channel.py", line 1058, in _send
  OSError: Socket is closed
  </code></pre>