mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
support winxp
This commit is contained in:
parent
5b708c45ed
commit
ae197b2183
|
@ -86,8 +86,11 @@ def main():
|
||||||
thr.daemon = True
|
thr.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
time.sleep(9001)
|
time.sleep(9001)
|
||||||
|
except:
|
||||||
|
print("bye")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -121,7 +121,7 @@ class HttpCli(object):
|
||||||
for ln in form_segm[1:]:
|
for ln in form_segm[1:]:
|
||||||
self.log(ln)
|
self.log(ln)
|
||||||
|
|
||||||
fn = "/dev/null"
|
fn = os.devnull
|
||||||
fn0 = "inc.{0:.6f}".format(time.time())
|
fn0 = "inc.{0:.6f}".format(time.time())
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
|
|
|
@ -37,8 +37,11 @@ class MpWorker(object):
|
||||||
thr.daemon = True
|
thr.daemon = True
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
|
try:
|
||||||
while True:
|
while True:
|
||||||
time.sleep(9001)
|
time.sleep(9001)
|
||||||
|
except:
|
||||||
|
self.logw("bye")
|
||||||
|
|
||||||
def log(self, src, msg):
|
def log(self, src, msg):
|
||||||
self.q_yield.put(["log", src, msg])
|
self.q_yield.put(["log", src, msg])
|
||||||
|
|
|
@ -8,8 +8,8 @@ import threading
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import calendar
|
import calendar
|
||||||
|
|
||||||
|
from .__init__ import *
|
||||||
from .msgsvc import *
|
from .msgsvc import *
|
||||||
from .mpsrv import *
|
|
||||||
|
|
||||||
|
|
||||||
class TcpSrv(object):
|
class TcpSrv(object):
|
||||||
|
@ -20,6 +20,8 @@ class TcpSrv(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
|
self.args = args
|
||||||
|
|
||||||
self.log_mutex = threading.Lock()
|
self.log_mutex = threading.Lock()
|
||||||
self.msgsvc = MsgSvc(self.log)
|
self.msgsvc = MsgSvc(self.log)
|
||||||
self.next_day = 0
|
self.next_day = 0
|
||||||
|
@ -46,12 +48,7 @@ class TcpSrv(object):
|
||||||
|
|
||||||
self.log("root", "listening @ {0}:{1}".format(bind_ip, bind_port))
|
self.log("root", "listening @ {0}:{1}".format(bind_ip, bind_port))
|
||||||
|
|
||||||
if args.j == 0:
|
httpsrv = self.create_server()
|
||||||
self.log("root", "multiprocessing disabled")
|
|
||||||
httpsrv = HttpSrv(args, self.log)
|
|
||||||
else:
|
|
||||||
httpsrv = MpSrv(args, self.log)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if httpsrv.num_clients() >= args.nc:
|
if httpsrv.num_clients() >= args.nc:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
@ -60,6 +57,52 @@ class TcpSrv(object):
|
||||||
sck, addr = srv.accept()
|
sck, addr = srv.accept()
|
||||||
httpsrv.accept(sck, addr)
|
httpsrv.accept(sck, addr)
|
||||||
|
|
||||||
|
def check_mp_support(self):
|
||||||
|
vmin = sys.version_info[1]
|
||||||
|
if WINDOWS:
|
||||||
|
if PY2:
|
||||||
|
# ForkingPickler doesn't support winsock
|
||||||
|
return False
|
||||||
|
elif vmin < 4:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
if not PY2 and vmin < 4:
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
# fails on py3.3, works on py2.7
|
||||||
|
from multiprocessing.reduction import ForkingPickler
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def create_server(self):
|
||||||
|
if self.args.j == 0:
|
||||||
|
self.log("root", "multiprocessing disabled by argument -j 0;")
|
||||||
|
return self.create_threading_server()
|
||||||
|
|
||||||
|
if not self.check_mp_support():
|
||||||
|
if WINDOWS:
|
||||||
|
self.log("root", "need python 3.4 or newer for multiprocessing;")
|
||||||
|
else:
|
||||||
|
self.log("root", "need python 2.7 or 3.4+ for multiprocessing;")
|
||||||
|
|
||||||
|
return self.create_threading_server()
|
||||||
|
|
||||||
|
return self.create_multiprocessing_server()
|
||||||
|
|
||||||
|
def create_threading_server(self):
|
||||||
|
from .httpsrv import HttpSrv
|
||||||
|
|
||||||
|
self.log("root", "cannot efficiently use multiple CPU cores")
|
||||||
|
return HttpSrv(self.args, self.log)
|
||||||
|
|
||||||
|
def create_multiprocessing_server(self):
|
||||||
|
from .mpsrv import MpSrv
|
||||||
|
|
||||||
|
return MpSrv(self.args, self.log)
|
||||||
|
|
||||||
def log(self, src, msg):
|
def log(self, src, msg):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if now >= self.next_day:
|
if now >= self.next_day:
|
||||||
|
|
Loading…
Reference in a new issue