temp_server.py 910 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. #
  3. import logging
  4. import argparse
  5. import multiprocessing
  6. #
  7. import throughput_server
  8. #
  9. if __name__ == '__main__':
  10. logging.basicConfig(level=logging.DEBUG)
  11. #
  12. parser = argparse.ArgumentParser(description='Test the network throughput (optionally through a proxy).')
  13. parser.add_argument('port', type=int, help='listen on port')
  14. parser.add_argument('--localhost', action='store_true', help='bind to 127.0.0.1 instead of 0.0.0.0')
  15. args = parser.parse_args()
  16. #
  17. if args.localhost:
  18. bind_to = ('127.0.0.1', args.port)
  19. else:
  20. bind_to = ('0.0.0.0', args.port)
  21. #
  22. stop_event = multiprocessing.Event()
  23. server = throughput_server.ThroughputServer(bind_to, None)
  24. try:
  25. server.run()
  26. except KeyboardInterrupt:
  27. print('')
  28. logging.debug('Server stopped (KeyboardInterrupt).')
  29. #
  30. results = server.results
  31. #
  32. for x in results:
  33. logging.info('{}'.format(x['results']['custom_data']))
  34. #
  35. #