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.
This commit is contained in:
		
							parent
							
								
									f62462d5f8
								
							
						
					
					
						commit
						805cea0a0b
					
				@ -51,7 +51,10 @@ def _prep_bins():
 | 
				
			|||||||
        return  # there are no prebuilts for this platform - nothing to do
 | 
					        return  # there are no prebuilts for this platform - nothing to do
 | 
				
			||||||
    files = map(lambda x: path.join(prebuilt_path, x), config["FILES"])
 | 
					    files = map(lambda x: path.join(prebuilt_path, x), config["FILES"])
 | 
				
			||||||
    for prebuilt_file in files:
 | 
					    for prebuilt_file in files:
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
            copy(path.join(prebuilt_path, prebuilt_file), package_root)
 | 
					            copy(path.join(prebuilt_path, prebuilt_file), package_root)
 | 
				
			||||||
 | 
					        except IOError:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_prep_bins()  # prepare before module imports
 | 
					_prep_bins()  # prepare before module imports
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -37,6 +37,7 @@ from os import path, urandom
 | 
				
			|||||||
from timeit import timeit
 | 
					from timeit import timeit
 | 
				
			||||||
from select import select
 | 
					from select import select
 | 
				
			||||||
from multiprocessing import Process
 | 
					from multiprocessing import Process
 | 
				
			||||||
 | 
					from multiprocessing.managers import BaseManager
 | 
				
			||||||
from dtls import do_patch
 | 
					from dtls import do_patch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AF_INET4_6 = socket.AF_INET
 | 
					AF_INET4_6 = socket.AF_INET
 | 
				
			||||||
@ -188,7 +189,11 @@ def server(sock_type, do_wrap, listen_addr):
 | 
				
			|||||||
            wrap.listen(0)
 | 
					            wrap.listen(0)
 | 
				
			||||||
    yield wrap.getsockname()
 | 
					    yield wrap.getsockname()
 | 
				
			||||||
    if do_wrap or sock_type == socket.SOCK_STREAM:
 | 
					    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:
 | 
					    else:
 | 
				
			||||||
        conn = wrap
 | 
					        conn = wrap
 | 
				
			||||||
    wrap.setblocking(False)
 | 
					    wrap.setblocking(False)
 | 
				
			||||||
@ -234,6 +239,7 @@ def server(sock_type, do_wrap, listen_addr):
 | 
				
			|||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def client(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)
 | 
					    sock = socket.socket(AF_INET4_6, sock_type)
 | 
				
			||||||
    if do_wrap:
 | 
					    if do_wrap:
 | 
				
			||||||
        wrap = ssl.wrap_socket(sock, ciphers="NULL")
 | 
					        wrap = ssl.wrap_socket(sock, ciphers="NULL")
 | 
				
			||||||
@ -291,15 +297,18 @@ def release_clients():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
MANAGER = None
 | 
					MANAGER = None
 | 
				
			||||||
QUEUE = None
 | 
					QUEUE = None
 | 
				
			||||||
 | 
					class Manager(BaseManager): pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def start_client_manager(port):
 | 
					def start_client_manager(port):
 | 
				
			||||||
    from multiprocessing.managers import BaseManager
 | 
					 | 
				
			||||||
    global MANAGER, QUEUE
 | 
					    global MANAGER, QUEUE
 | 
				
			||||||
    make_client_manager()
 | 
					    make_client_manager()
 | 
				
			||||||
    class Manager(BaseManager): pass
 | 
					 | 
				
			||||||
    Manager.register("get_queue", get_queue)
 | 
					    Manager.register("get_queue", get_queue)
 | 
				
			||||||
    Manager.register("release_clients", release_clients)
 | 
					    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)
 | 
					    MANAGER.start(make_client_manager)
 | 
				
			||||||
    QUEUE = MANAGER.get_queue()
 | 
					    QUEUE = MANAGER.get_queue()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -311,9 +320,6 @@ def stop_client_manager():
 | 
				
			|||||||
    MANAGER = None
 | 
					    MANAGER = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def remote_client(manager_address):
 | 
					def remote_client(manager_address):
 | 
				
			||||||
    from multiprocessing.managers import BaseManager
 | 
					 | 
				
			||||||
    do_patch()
 | 
					 | 
				
			||||||
    class Manager(BaseManager): pass
 | 
					 | 
				
			||||||
    Manager.register("get_queue")
 | 
					    Manager.register("get_queue")
 | 
				
			||||||
    manager = Manager(manager_address, COMM_KEY)
 | 
					    manager = Manager(manager_address, COMM_KEY)
 | 
				
			||||||
    manager.connect()
 | 
					    manager.connect()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user