title: Run server and client in the same file - python
body: <p>I am using tftpy and need to create a server, then a client to download/upload some file and then I can close the server.</p>
  
  <p>I was thinking on using multiprocessing to accomplish this but I don't know how to close the server gracefully. The last resort will be to use terminate() but perhaps there is a better method (perhaps an easier one not using multiprocessing). I also know about multiprocessing.Event() but I don't know how run_sv() method will keep listening</p>
  
  <p>Here is the code:</p>
  
  <pre><code>import multiprocessing
  import tftpy
  
  def run_sv():
      name = multiprocessing.current_process().name
      print name, 'Starting sv'
      server = tftpy.TftpServer('./rootf')
      server.listen('0.0.0.0', 69)
      print name, 'Exiting sv'
  
  def run_cl():
      name = multiprocessing.current_process().name
      print name, 'Starting cl'
      client = tftpy.TftpClient('127.0.0.1', 69)
      client.download('aaa.txt', './downf/zzz.txt')
      print name, 'Exiting cl'
  
  if __name__ == '__main__':
      service = multiprocessing.Process(name='my_sv', target=run_sv)
      worker_1 = multiprocessing.Process(name='my_cl', target=run_cl)
  
      service.start()
      worker_1.start()
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>my_sv Starting sv
  my_cl Starting cl
  my_cl Exiting cl
  </code></pre>
  
  <p>and of course it hangs there.</p>