def _wait_for_spot_request_fulfillment(conn, requests, fulfilled_requests=[]):
 if (len(requests) == 0):
  reservations = conn.get_all_instances(instance_ids=[r.instance_id for r in fulfilled_requests])
  return [r.instances[0] for r in reservations]
 else:
  time.sleep(10)
  print '.'
 requests = conn.get_all_spot_instance_requests(request_ids=[req.id for req in requests])
 for req in requests:
  if (req.status.code == 'fulfilled'):
   fulfilled_requests.append(req)
   print 'spot bee `{}` joined the swarm.'.format(req.instance_id)
 return _wait_for_spot_request_fulfillment(conn, [r for r in requests if (r not in fulfilled_requests)], fulfilled_requests)

def _wait_for_spot_request_fulfillment ( conn , requests , fulfilled_requests = [ ] ) : if ( len ( requests ) == 0 ) : reservations = conn . get_all_instances ( instance_ids = [ r . instance_id for r in fulfilled_requests ] ) return [ r . instances [ 0 ] for r in reservations ] else : time . sleep ( 10 ) print '.' requests = conn . get_all_spot_instance_requests ( request_ids = [ req . id for req in requests ] ) for req in requests : if ( req . status . code == 'fulfilled' ) : fulfilled_requests . append ( req ) print 'spot bee `{}` joined the swarm.' . format ( req . instance_id ) return _wait_for_spot_request_fulfillment ( conn , [ r for r in requests if ( r not in fulfilled_requests ) ] , fulfilled_requests )
wait until all spot requests are fulfilled .