title: How to make a separate thread for a function - Python?
body: <p>On this part of python script below, I want to use a sftp.put() in a separate thread/processus and kill it after a while, all in the same script. I don’t know how to write this using Thread or multiprocessing.</p>
  
  <p>Is someone may show me a simple way to do it please? </p>
  
  <p><strong>Ubuntu 18.04,
  paramiko 2.6.0</strong></p>
  
  <pre><code>[...]
  raspi = paramiko.SSHClient()
  raspi.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  raspi.connect(ip , username= "", password= "" , timeout=10)
  sftp = raspi.open_sftp()        
  
  [...]   
  
  sftp.put(source, destination , callback=None, confirm=True)  
  
  raspi.close()
  
  [...]
  </code></pre>
  
  <p><strong>Update 1</strong></p>
  
  <p>Ok, so this code is working, but if I use all the arguments of the sftp.put(), he doesn't work and return a syntax error:</p>
  
  <pre><code> [...]
      raspi = paramiko.SSHClient()
      raspi.set_missing_host_key_policy(paramiko.AutoAddPolicy())
      raspi.connect(ip , username= "", password= "" , timeout=10)
      sftp = raspi.open_sftp()        
  
      [...]   
  
      th = threading.Thread(target=sftp.put, args=(source, destination))
      th.start()
      th.join()
  
      raspi.close()
  
      [...]
  </code></pre>
  
  <p>Don't work with (invalid syntax):</p>
  
  <pre><code>th = threading.Thread(target=sftp.put, args=(source, destination, callback=None, confirm=True))
  </code></pre>