|
|
@@ -4,6 +4,7 @@ import time
|
|
|
import subprocess
|
|
|
import sys
|
|
|
import os
|
|
|
+import threading
|
|
|
args = None
|
|
|
outerthread = None
|
|
|
|
|
|
@@ -25,6 +26,13 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
|
|
|
self.wfile.write(data)
|
|
|
self.close_connection = True
|
|
|
|
|
|
+def runServer(fileName):
|
|
|
+ httpd = HTTPServer(('localhost', 0), SimpleHTTPRequestHandler)
|
|
|
+ with open(fileName,"w") as f:
|
|
|
+ f.write('http://localhost:{}/test'.format(httpd.socket.getsockname()[1]))
|
|
|
+ httpd.handle_request()
|
|
|
+ os.remove(fileName)
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
parser = argparse.ArgumentParser()
|
|
|
parser.add_argument('--speed_limit', help='transfer rate limitation', action='store_true',default=False)
|
|
|
@@ -35,8 +43,7 @@ if __name__ == "__main__":
|
|
|
if not args.subprocess:
|
|
|
subprocess.Popen([sys.executable]+sys.argv+['--subprocess'],stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL,stdout=subprocess.DEVNULL)
|
|
|
else:
|
|
|
- httpd = HTTPServer(('localhost', 0), SimpleHTTPRequestHandler)
|
|
|
- with open(args.file,"w") as f:
|
|
|
- f.write('http://localhost:{}/test'.format(httpd.socket.getsockname()[1]))
|
|
|
- httpd.handle_request()
|
|
|
- os.remove(args.file)
|
|
|
+ serverThread = threading.Thread(target=runServer,args=(args.file,))
|
|
|
+ serverThread.daemon = True
|
|
|
+ serverThread.start()
|
|
|
+ serverThread.join(15)
|