win32 platform support:
* no daemonizing support * no SIGCHLD signal * no multiprocessing support * override copyfile so we can retry on WSAEWOULDBLOCK
This commit is contained in:
parent
fd846b3f5d
commit
966ba9eb6f
|
|
@ -50,10 +50,15 @@ except:
|
||||||
return struct.unpack(fmt, slice)
|
return struct.unpack(fmt, slice)
|
||||||
|
|
||||||
# Degraded functionality if these imports are missing
|
# Degraded functionality if these imports are missing
|
||||||
for mod, msg in [('numpy', 'HyBi protocol will be slower'),
|
OPTIONAL_FEATURES = [
|
||||||
('ssl', 'TLS/SSL/wss is disabled'),
|
('numpy', 'HyBi protocol will be slower'),
|
||||||
('multiprocessing', 'Multi-Processing is disabled'),
|
('ssl', 'TLS/SSL/wss is disabled'),
|
||||||
('resource', 'daemonizing is disabled')]:
|
('multiprocessing', 'Multi-Processing is disabled'),
|
||||||
|
]
|
||||||
|
if not sys.platform.startswith("win"):
|
||||||
|
#resource module is not available on Windows
|
||||||
|
OPTIONAL_FEATURES.append(('resource', 'daemonizing is disabled'))
|
||||||
|
for mod, msg in OPTIONAL_FEATURES:
|
||||||
try:
|
try:
|
||||||
globals()[mod] = __import__(mod)
|
globals()[mod] = __import__(mod)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -535,6 +540,20 @@ class WebSocketRequestHandler(SimpleHTTPRequestHandler):
|
||||||
else:
|
else:
|
||||||
SimpleHTTPRequestHandler.do_GET(self)
|
SimpleHTTPRequestHandler.do_GET(self)
|
||||||
|
|
||||||
|
def copyfile(self, source, outputfile):
|
||||||
|
"""Adds retry code for WSAEWOULDBLOCK on MS Windows"""
|
||||||
|
if not sys.platform.startswith("win"):
|
||||||
|
return SimpleHTTPRequestHandler.copyfile(self, source, outputfile)
|
||||||
|
import shutil
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
shutil.copyfileobj(source, outputfile)
|
||||||
|
return
|
||||||
|
except (IOError, OSError) as e:
|
||||||
|
if e[0]==errno.WSAEWOULDBLOCK:
|
||||||
|
continue
|
||||||
|
raise
|
||||||
|
|
||||||
def list_directory(self, path):
|
def list_directory(self, path):
|
||||||
if self.file_only:
|
if self.file_only:
|
||||||
self.send_error(404, "No such file")
|
self.send_error(404, "No such file")
|
||||||
|
|
@ -972,17 +991,20 @@ class WebSocketServer(object):
|
||||||
original_signals = {
|
original_signals = {
|
||||||
signal.SIGINT: signal.getsignal(signal.SIGINT),
|
signal.SIGINT: signal.getsignal(signal.SIGINT),
|
||||||
signal.SIGTERM: signal.getsignal(signal.SIGTERM),
|
signal.SIGTERM: signal.getsignal(signal.SIGTERM),
|
||||||
signal.SIGCHLD: signal.getsignal(signal.SIGCHLD),
|
|
||||||
}
|
}
|
||||||
signal.signal(signal.SIGINT, self.do_SIGINT)
|
signal.signal(signal.SIGINT, self.do_SIGINT)
|
||||||
signal.signal(signal.SIGTERM, self.do_SIGTERM)
|
signal.signal(signal.SIGTERM, self.do_SIGTERM)
|
||||||
if not multiprocessing:
|
#SIGCHLD is only available on posix:
|
||||||
# os.fork() (python 2.4) child reaper
|
SIGCHLD = getattr(signal, "SIGCHLD", None)
|
||||||
signal.signal(signal.SIGCHLD, self.fallback_SIGCHLD)
|
if SIGCHLD:
|
||||||
else:
|
original_signals[SIGCHLD] = signal.getsignal(SIGCHLD)
|
||||||
# make sure that _cleanup is called when children die
|
if not multiprocessing:
|
||||||
# by calling active_children on SIGCHLD
|
# os.fork() (python 2.4) child reaper
|
||||||
signal.signal(signal.SIGCHLD, self.multiprocessing_SIGCHLD)
|
signal.signal(SIGCHLD, self.fallback_SIGCHLD)
|
||||||
|
else:
|
||||||
|
# make sure that _cleanup is called when children die
|
||||||
|
# by calling active_children on SIGCHLD
|
||||||
|
signal.signal(SIGCHLD, self.multiprocessing_SIGCHLD)
|
||||||
|
|
||||||
last_active_time = self.launch_time
|
last_active_time = self.launch_time
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,8 @@ class WebSocketProxy(websocket.WebSocketServer):
|
||||||
|
|
||||||
def __init__(self, RequestHandlerClass=ProxyRequestHandler, *args, **kwargs):
|
def __init__(self, RequestHandlerClass=ProxyRequestHandler, *args, **kwargs):
|
||||||
# Save off proxy specific options
|
# Save off proxy specific options
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
kwargs.pop("multiprocessing_fork", None)
|
||||||
self.target_host = kwargs.pop('target_host', None)
|
self.target_host = kwargs.pop('target_host', None)
|
||||||
self.target_port = kwargs.pop('target_port', None)
|
self.target_port = kwargs.pop('target_port', None)
|
||||||
self.wrap_cmd = kwargs.pop('wrap_cmd', None)
|
self.wrap_cmd = kwargs.pop('wrap_cmd', None)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue