def wait_for_spot_instance_requests(self, requests, timeout=None, callback=None):
        t0 = time.time()
        pending_states = ['pending-evaluation', 'pending-fulfillment']
        pending = {r.id: r for r in requests}
        fulfilled = {}
        unfulfilled = {}

        while len(pending) > 0:
            if timeout and time.time() > t0 + timeout:
                raise TimeoutError(
                    "Timed out waiting for spot instances to be fulfilled.",
                    fulfilled=fulfilled,
                    unfulfilled=unfulfilled,
                    pending=pending
                    )

            time.sleep(1)
            spot_requests = self.ec2.get_all_spot_instance_requests(
                request_ids=pending.keys()
                )
            status = {}
            for request in spot_requests:
                status_key = '%s - %s' % (request.state, request.status.code)
                if status_key not in status:
                    status[status_key] = []
                status[status_key].append(request.id)
                if request.state == 'active':
                    fulfilled[request.id] = request
                    del pending[request.id]
                elif request.state != 'open' or request.status.code not in pending_states:
                    unfulfilled[request.id] = request
                    del pending[request.id]
            if callback:
                callback(status)

        return (fulfilled.values(), unfulfilled.values())
dataset/ETHPy150Open ufora/ufora/packages/python/pyfora/aws/Launcher.py/Launcher.wait_for_spot_instance_requests/original