From 805cea0a0bae2c1693a980599dca68f940e34b44 Mon Sep 17 00:00:00 2001 From: Ray Brown Date: Mon, 24 Dec 2012 12:30:55 -0800 Subject: [PATCH] Performance test port to Windows This patch allows the module test_perf.py to be run on Windows. It contains fixes primarily accounting for differences in the implementation of the multiprocessing module among platforms. --- dtls/__init__.py | 5 ++++- dtls/test/test_perf.py | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/dtls/__init__.py b/dtls/__init__.py index 83a62d3..7912b1e 100644 --- a/dtls/__init__.py +++ b/dtls/__init__.py @@ -51,7 +51,10 @@ def _prep_bins(): return # there are no prebuilts for this platform - nothing to do files = map(lambda x: path.join(prebuilt_path, x), config["FILES"]) for prebuilt_file in files: - copy(path.join(prebuilt_path, prebuilt_file), package_root) + try: + copy(path.join(prebuilt_path, prebuilt_file), package_root) + except IOError: + pass _prep_bins() # prepare before module imports diff --git a/dtls/test/test_perf.py b/dtls/test/test_perf.py index 6f2aadc..ef860b4 100644 --- a/dtls/test/test_perf.py +++ b/dtls/test/test_perf.py @@ -37,6 +37,7 @@ from os import path, urandom from timeit import timeit from select import select from multiprocessing import Process +from multiprocessing.managers import BaseManager from dtls import do_patch AF_INET4_6 = socket.AF_INET @@ -188,7 +189,11 @@ def server(sock_type, do_wrap, listen_addr): wrap.listen(0) yield wrap.getsockname() if do_wrap or sock_type == socket.SOCK_STREAM: - conn = wrap.accept()[0] + while True: + acc_res = wrap.accept() + if acc_res: + break + conn = acc_res[0] else: conn = wrap wrap.setblocking(False) @@ -234,6 +239,7 @@ def server(sock_type, do_wrap, listen_addr): # def client(sock_type, do_wrap, listen_addr): + do_patch() # we might be in a new process sock = socket.socket(AF_INET4_6, sock_type) if do_wrap: wrap = ssl.wrap_socket(sock, ciphers="NULL") @@ -291,15 +297,18 @@ def release_clients(): MANAGER = None QUEUE = None +class Manager(BaseManager): pass def start_client_manager(port): - from multiprocessing.managers import BaseManager global MANAGER, QUEUE make_client_manager() - class Manager(BaseManager): pass Manager.register("get_queue", get_queue) Manager.register("release_clients", release_clients) - MANAGER = Manager(('', port), COMM_KEY) + if sys.platform.startswith('win'): + addr = socket.gethostname(), port + else: + addr = '', port + MANAGER = Manager(addr, COMM_KEY) MANAGER.start(make_client_manager) QUEUE = MANAGER.get_queue() @@ -311,9 +320,6 @@ def stop_client_manager(): MANAGER = None def remote_client(manager_address): - from multiprocessing.managers import BaseManager - do_patch() - class Manager(BaseManager): pass Manager.register("get_queue") manager = Manager(manager_address, COMM_KEY) manager.connect()