#NEWLINE# @ contextmanager #NEWLINE# def run( self , count ) : #NEWLINE# #INDENT# sshd_ports = [ ] #NEWLINE# for try_port in random . sample ( range ( 10000 , 11000 ) , count ) : #NEWLINE# #INDENT# while can_connect ( try_port ) : #NEWLINE# #INDENT# try_port += 1 #NEWLINE# #UNINDENT# sshd_ports . append ( try_port ) #NEWLINE# #UNINDENT# subprocesses = [ ] #NEWLINE# for port in sshd_ports : #NEWLINE# #INDENT# subprocesses . append ( subprocess . Popen ( [ '/usr/sbin/sshd' , '-p{}' . format ( port ) , '-f{}' . format ( self . sshd_config_path ) , '-e' , '-D' ] , cwd = str ( self . tmpdir ) ) ) #NEWLINE# #UNINDENT# @ retry ( stop_max_delay = 1000 , retry_on_result = ( lambda x : ( x is False ) ) ) #NEWLINE# def check_server( port ) : #NEWLINE# #INDENT# return can_connect ( port ) #NEWLINE# #UNINDENT# for port in sshd_ports : #NEWLINE# #INDENT# check_server ( s ) #NEWLINE# #UNINDENT# ( yield sshd_ports ) #NEWLINE# for s in subprocesses : #NEWLINE# #INDENT# s . kill ( )