-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
34 lines (28 loc) · 791 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/env python
#https://github.com/Nakiami/MultithreadedSimpleHTTPServer (GPL)
try:
# Python 2.x
from SocketServer import ThreadingMixIn
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
except ImportError:
# Python 3.x
from socketserver import ThreadingMixIn
from http.server import SimpleHTTPRequestHandler, HTTPServer
class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
pass
import sys
import os
if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 8000
if sys.argv[2:]:
os.chdir(sys.argv[2])
server = ThreadingSimpleServer(('', port), SimpleHTTPRequestHandler)
try:
while 1:
sys.stdout.flush()
server.handle_request()
except KeyboardInterrupt:
print("Finished")